crossjoin/css
最新稳定版本:v1.0.3
Composer 安装命令:
composer require crossjoin/css
包简介
CSS reader and writer with full CSS3 support, already supporting huge parts of the current CSS4 spec. It supports media queries, comments, value optimization and more... It offers full Unicode support and can handle also large CSS sources. Requires PHP 5.4+.
README 文档
README
#CSS reader and writer
##Introduction CSS reader and writer with full CSS3 support, already supporting huge parts of the current CSS4 spec. It supports media queries, comments, value optimization and more... It offers full Unicode support and can handle also large CSS sources.
##Installation This is a composer package. See the composer website for basic installation information.
Add the following line to your composer.json file:
{
"require": {
"crossjoin/css": "1.0.*"
}
}
###Requirements
- PHP 5.4+
- Multibyte String (mbstring) extension
- DOM extension (to extract CSS from HTML sources)
##Features
- Full CSS3 support
- Full Unicode support
- Support for huge parts of CSS4
- Supports at-rules with an unlimited level of nesting
- Supports CSS comments
- Can handle large, compressed CSS files
- Integrated checks for invalid CSS
- ...
##Basic usage
###Reading CSS You can read the CSS information from different sources.
// Read CSS file $cssFileName = "path/to/file.css"; $reader = new \Crossjoin\Css\Reader\CssFile($cssFileName); // Read CSS string $cssString = "body { background:red; }"; $reader = new \Crossjoin\Css\Reader\CssFile($cssString); // Extract CSS from <style> tags in a HTML file // (multiple tags are merges to one style sheet) $htmlFileName = "path/to/file.html"; $reader = new \Crossjoin\Css\Reader\HtmlFile($htmlFileName); // Extract CSS from <style> tags in a HTML string // (multiple tags are merges to one style sheet) $htmlString = "<html><head><style>body{color:red;}</style></head><body></body></html>"; $reader = new \Crossjoin\Css\Reader\HtmlFile($htmlString);
###Charset detection The charset of the CSS file is detected automatically (depending on Byte-Order-Markers or a charset rule within the CSS) and defaults to "UTF-8". You can change the default value by setting the environment encoding.
// Sets the environment encoding of the referencing (!) document, e.g. if defined // in a link tag of an HTML page. // This is used as a fall back value to determine the charset of the CSS file. $reader->setEnvironmentEncoding("UTF-8");
###Writing CSS The writer can create CSS in different formats.
// Gets the CSS content in compact format (no comments, no line breaks,...) $writer = new \Crossjoin\Css\Writer\Compact($reader->getStyleSheet()); $cssContent = $writer->getContent(); // Gets the CSS content in prettified format // (with comments, line breaks, indentations,...) $writer = new \Crossjoin\Css\Writer\Pretty($reader->getStyleSheet()); $cssContent = $writer->getContent();
###Error handling While parsing the CSS source, the content is checked for invalid rules, selectors and declarations. Furthermore the reader and the writer do additional checks regarding the composition of the rules, e.g. invalid rule positions or unnecessary empty rules.
$cssString = 'body{color:black} @charset "UTF-8"; @media print{@page{margin:1cm;}}'; $reader = new \Crossjoin\Css\Reader\CssString($cssString); $writer = new \Crossjoin\Css\Writer\Pretty($reader->getStyleSheet()); $content = $writer->getContent(); $errors = $writer->getErrors(); print_r($content); // body { color: black; } print_r($errors); // Array ( // [0] => Ignored @charset rule, because at wrong position in style sheet. // [1] => Rule instance of type 'Crossjoin\Css\Format\Rule\AtPage\PageRule' // not allowed in conditional group rule of type // 'Crossjoin\Css\Format\Rule\AtMedia\MediaRule'. // [2] => Empty media at-rule '@media print' ignored. // )
##Advanced usage TODO
##To Do
- Additional checks for valid CSS rules, properties and values
- Additional optimizations of CSS properties and values
- Optimized auto-correction of invalid CSS, following the specs (example)
- Support for CSS Paged Media Module Level 3 (page type selectors, margin at-rules)
- Support for "supports" in import at-rule (not final)
crossjoin/css 适用场景与选型建议
crossjoin/css 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 47.5k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2015 年 05 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「css」 「css parser」 「css reader」 「css writer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 crossjoin/css 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 crossjoin/css 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 crossjoin/css 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Twig extension to insert css as inline styles with a tag
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
Caching and compression for Twig assets (JavaScript and CSS).
An MT940 bank statement parser for PHP
Laravel integration for the jsonapi.org parser
Define your own css rule-sets for the TYPO3 CMS backend.
统计信息
- 总下载量: 47.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 16
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-05-27