summaryrefslogtreecommitdiff
path: root/lib/exe
diff options
context:
space:
mode:
authorfurun <furun@arcor.de>2013-10-15 11:34:31 +0200
committerAndreas Gohr <gohr@cosmocode.de>2013-10-15 11:34:31 +0200
commit205907a73eaf15c53de98f153e90890706e79cbe (patch)
tree3c4737f616715f923f39905b072f81a9d7fc6259 /lib/exe
parent51447840eb55520faba63598e83b24ac8f016501 (diff)
downloadrpg-205907a73eaf15c53de98f153e90890706e79cbe.tar.gz
rpg-205907a73eaf15c53de98f153e90890706e79cbe.tar.bz2
compact some CSS styles to their shorthand syntax FS#2509
Diffstat (limited to 'lib/exe')
-rw-r--r--lib/exe/css.php13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/exe/css.php b/lib/exe/css.php
index afba5fc02..6dfdf06e8 100644
--- a/lib/exe/css.php
+++ b/lib/exe/css.php
@@ -473,8 +473,19 @@ function css_compress($css){
$css = preg_replace('/ ?([;,{}\/]) ?/','\\1',$css);
$css = preg_replace('/ ?: /',':',$css);
+ // number compression
+ $css = preg_replace('/([: ])0+(\.\d+?)0*((?:pt|pc|in|mm|cm|em|ex|px)\b|%)(?=[^\{]*[;\}])/', '$1$2$3', $css); // "0.1em" to ".1em", "1.10em" to "1.1em"
+ $css = preg_replace('/([: ])\.(0)+((?:pt|pc|in|mm|cm|em|ex|px)\b|%)(?=[^\{]*[;\}])/', '$1$2', $css); // ".0em" to "0"
+ $css = preg_replace('/([: ]0)0*(\.0*)?((?:pt|pc|in|mm|cm|em|ex|px)(?=[^\{]*[;\}])\b|%)/', '$1', $css); // "0.0em" to "0"
+ $css = preg_replace('/([: ]\d+)(\.0*)((?:pt|pc|in|mm|cm|em|ex|px)(?=[^\{]*[;\}])\b|%)/', '$1$3', $css); // "1.0em" to "1em"
+ $css = preg_replace('/([: ])0+(\d+|\d*\.\d+)((?:pt|pc|in|mm|cm|em|ex|px)(?=[^\{]*[;\}])\b|%)/', '$1$2$3', $css); // "001em" to "1em"
+
+ // shorten attributes (1em 1em 1em 1em -> 1em)
+ $css = preg_replace('/(?<![\w\-])((?:margin|padding|border|border-(?:width|radius)):)([\w\.]+)( \2)+(?=[;\}]| !)/', '$1$2', $css); // "1em 1em 1em 1em" to "1em"
+ $css = preg_replace('/(?<![\w\-])((?:margin|padding|border|border-(?:width)):)([\w\.]+) ([\w\.]+) \2 \3(?=[;\}]| !)/', '$1$2 $3', $css); // "1em 2em 1em 2em" to "1em 2em"
+
// shorten colors
- $css = preg_replace("/#([0-9a-fA-F]{1})\\1([0-9a-fA-F]{1})\\2([0-9a-fA-F]{1})\\3/", "#\\1\\2\\3",$css);
+ $css = preg_replace("/#([0-9a-fA-F]{1})\\1([0-9a-fA-F]{1})\\2([0-9a-fA-F]{1})\\3(?=[^\{]*[;\}])/", "#\\1\\2\\3", $css);
return $css;
}