开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
forked from 黎晓/JavaScript
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
项目仓库所选许可证以仓库主分支所使用许可证为准
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
JavaScript
/
lib
/
Minify
/
YUI
/
CssCompressor.php
JavaScript
/
lib
/
Minify
/
YUI
/
CssCompressor.php
CssCompressor.php 6.16 KB
一键复制 编辑 原始数据 按行查看 历史
刘海明 提交于 2014年12月01日 12:22 +08:00 . 新建项目
<?php
/**
* Class Minify_YUI_CssCompressor
* @package Minify
*
* YUI Compressor
* Author: Julien Lecomte - http://www.julienlecomte.net/
* Author: Isaac Schlueter - http://foohack.com/
* Author: Stoyan Stefanov - http://phpied.com/
* Author: Steve Clay - http://www.mrclay.org/ (PHP port)
* Copyright (c) 2009 Yahoo! Inc. All rights reserved.
* The copyrights embodied in the content of this file are licensed
* by Yahoo! Inc. under the BSD (revised) open source license.
*/
/**
* Compress CSS (incomplete DO NOT USE)
*
* @see https://github.com/yui/yuicompressor/blob/master/src/com/yahoo/platform/yui/compressor/CssCompressor.java
*
* @package Minify
*/
class Minify_YUI_CssCompressor {
/**
* Minify a CSS string
*
* @param string $css
*
* @return string
*/
public function compress($css, $linebreakpos = 0)
{
$css = str_replace("\r\n", "\n", $css);
/**
* @todo comment removal
* @todo re-port from newer Java version
*/
// Normalize all whitespace strings to single spaces. Easier to work with that way.
$css = preg_replace('@\s+@', ' ', $css);
// Make a pseudo class for the Box Model Hack
$css = preg_replace("@\"\\\\\"}\\\\\"\"@", "___PSEUDOCLASSBMH___", $css);
// Remove the spaces before the things that should not have spaces before them.
// But, be careful not to turn "p :link {...}" into "p:link{...}"
// Swap out any pseudo-class colons with the token, and then swap back.
$css = preg_replace_callback("@(^|\\})(([^\\{:])+:)+([^\\{]*\\{)@", array($this, '_removeSpacesCB'), $css);
$css = preg_replace("@\\s+([!{};:>+\\(\\)\\],])@", "1ドル", $css);
$css = str_replace("___PSEUDOCLASSCOLON___", ":", $css);
// Remove the spaces after the things that should not have spaces after them.
$css = preg_replace("@([!{}:;>+\\(\\[,])\\s+@", "1ドル", $css);
// Add the semicolon where it's missing.
$css = preg_replace("@([^;\\}])}@", "1ドル;}", $css);
// Replace 0(px,em,%) with 0.
$css = preg_replace("@([\\s:])(0)(px|em|%|in|cm|mm|pc|pt|ex)@", "1ドル2ドル", $css);
// Replace 0 0 0 0; with 0.
$css = str_replace(":0 0 0 0;", ":0;", $css);
$css = str_replace(":0 0 0;", ":0;", $css);
$css = str_replace(":0 0;", ":0;", $css);
// Replace background-position:0; with background-position:0 0;
$css = str_replace("background-position:0;", "background-position:0 0;", $css);
// Replace 0.6 to .6, but only when preceded by : or a white-space
$css = preg_replace("@(:|\\s)0+\\.(\\d+)@", "1ドル.2ドル", $css);
// Shorten colors from rgb(51,102,153) to #336699
// This makes it more likely that it'll get further compressed in the next step.
$css = preg_replace_callback("@rgb\\s*\\(\\s*([0-9,\\s]+)\\s*\\)@", array($this, '_shortenRgbCB'), $css);
// Shorten colors from #AABBCC to #ABC. Note that we want to make sure
// the color is not preceded by either ", " or =. Indeed, the property
// filter: chroma(color="#FFFFFF");
// would become
// filter: chroma(color="#FFF");
// which makes the filter break in IE.
$css = preg_replace_callback("@([^\"'=\\s])(\\s*)#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])@", array($this, '_shortenHexCB'), $css);
// Remove empty rules.
$css = preg_replace("@[^\\}]+\\{;\\}@", "", $css);
$linebreakpos = isset($this->_options['linebreakpos'])
? $this->_options['linebreakpos']
: 0;
if ($linebreakpos > 0) {
// Some source control tools don't like it when files containing lines longer
// than, say 8000 characters, are checked in. The linebreak option is used in
// that case to split long lines after a specific column.
$i = 0;
$linestartpos = 0;
$sb = $css;
// make sure strlen returns byte count
$mbIntEnc = null;
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
$mbIntEnc = mb_internal_encoding();
mb_internal_encoding('8bit');
}
$sbLength = strlen($css);
while ($i < $sbLength) {
$c = $sb[$i++];
if ($c === '}' && $i - $linestartpos > $linebreakpos) {
$sb = substr_replace($sb, "\n", $i, 0);
$sbLength++;
$linestartpos = $i;
}
}
$css = $sb;
// undo potential mb_encoding change
if ($mbIntEnc !== null) {
mb_internal_encoding($mbIntEnc);
}
}
// Replace the pseudo class for the Box Model Hack
$css = str_replace("___PSEUDOCLASSBMH___", "\"\\\\\"}\\\\\"\"", $css);
// Replace multiple semi-colons in a row by a single one
// See SF bug #1980989
$css = preg_replace("@;;+@", ";", $css);
// prevent triggering IE6 bug: http://www.crankygeek.com/ie6pebug/
$css = preg_replace('/:first-l(etter|ine)\\{/', ':first-l1ドル {', $css);
// Trim the final string (for any leading or trailing white spaces)
$css = trim($css);
return $css;
}
protected function _removeSpacesCB($m)
{
return str_replace(':', '___PSEUDOCLASSCOLON___', $m[0]);
}
protected function _shortenRgbCB($m)
{
$rgbcolors = explode(',', $m[1]);
$hexcolor = '#';
for ($i = 0; $i < count($rgbcolors); $i++) {
$val = round($rgbcolors[$i]);
if ($val < 16) {
$hexcolor .= '0';
}
$hexcolor .= dechex($val);
}
return $hexcolor;
}
protected function _shortenHexCB($m)
{
// Test for AABBCC pattern
if ((strtolower($m[3])===strtolower($m[4])) &&
(strtolower($m[5])===strtolower($m[6])) &&
(strtolower($m[7])===strtolower($m[8]))) {
return $m[1] . $m[2] . "#" . $m[3] . $m[5] . $m[7];
} else {
return $m[0];
}
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/thinkerdev/JavaScript.git
git@gitee.com:thinkerdev/JavaScript.git
thinkerdev
JavaScript
JavaScript
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /