Material-Color/generate.php

103 lines
1.9 KiB
PHP
Raw Normal View History

2018-01-28 00:06:27 -07:00
<?php
2018-01-28 18:15:24 -07:00
$use_variables = false;
2018-01-28 00:06:27 -07:00
$classes = ["alert", "badge", "btn", "bg", "list-group-item"];
$colors = [
"red" => "#f44336",
"pink" => "#e91e63",
"purple" => "#9c27b0",
"deep-purple" => "#673ab7",
"indigo" => "#3f51b5",
"blue" => "#2196f3",
"light-blue" => "#03a9f4",
"cyan" => "#00bcd4",
"teal" => "#009688",
"green" => "#4caf50",
"light-green" => "#8bc34a",
"lime" => "#cddc39",
"yellow" => "#ffeb3b",
"amber" => "#ffc107",
"orange" => "#ff9800",
"deep-orange" => "#ff5722",
"brown" => "#795548",
"grey" => "#9e9e9e",
2018-01-28 18:15:24 -07:00
"blue-grey" => "#607d8b"
2018-01-28 00:06:27 -07:00
];
$texts = [
2018-01-28 18:15:24 -07:00
"red" => "white",
"pink" => "white",
"purple" => "white",
"deep-purple" => "white",
"indigo" => "white",
"blue" => "white",
"light-blue" => "black",
"cyan" => "black",
"teal" => "white",
"green" => "white",
"light-green" => "black",
"lime" => "black",
"yellow" => "black",
"amber" => "black",
"orange" => "black",
"deep-orange" => "white",
"brown" => "white",
"grey" => "black",
2018-01-28 00:06:27 -07:00
"blue-grey" => "white"
];
2018-01-28 18:15:24 -07:00
/* License header */
$year = date('Y');
echo <<<END
/* Material-Color.css
* Copyright (c) $year Netsyms Technologies
* MIT License
* https://source.netsyms.com/Netsyms/Material-Color
*/
END;
/* Make CSS variables */
if ($use_variables) {
echo ":root {\n";
foreach ($colors as $k => $v) {
if (strpos($k, "text-") !== FALSE) {
continue;
}
echo "\t--material-color-$k: $v;\n";
2018-01-28 00:06:27 -07:00
}
2018-01-28 18:15:24 -07:00
echo "}\n\n";
2018-01-28 00:06:27 -07:00
}
2018-01-28 18:15:24 -07:00
/* The fun bit */
2018-01-28 00:06:27 -07:00
foreach ($classes as $c) {
foreach ($colors as $k => $v) {
$textcolor = $texts[$k];
2018-01-28 18:15:24 -07:00
// Save a few bytes
if ($textcolor == "white") {
$textcolor = "#fff";
} else if ($textcolor == "black") {
$textcolor = "#000";
}
// Class and background color
echo ".$c-$k {\n\tbackground-color: ";
if ($use_variables) {
echo "var(--material-color-$k)";
} else {
echo $v;
}
echo ";\n";
// Text color
if ($c != "bg") {
echo "\tcolor: $textcolor;\n";
}
echo "}\n";
2018-01-28 00:06:27 -07:00
}
}
?>