Download the PHP package tbela99/css without Composer
On this page you can find all versions of the php package tbela99/css. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package css
Short Description A CSS parser and minifier written in PHP
License MIT LGPL-3.0-or-later
Homepage https://github.com/tbela99/css
Informations about the package css
CSS (A CSS parser and minifier written in PHP)
A CSS parser, beautifier and minifier written in PHP. It supports the following features
Features
- multibyte characters encoding
- sourcemap
- multiprocessing: process large CSS input very fast
- CSS Nesting module
- partially implemented CSS Syntax module level 3
- partial CSS validation
- CSS colors module level 4
- parse and render CSS
- optimize css:
- merge duplicate rules
- remove duplicate declarations
- remove empty rules
- compute css shorthand (margin, padding, outline, border-radius, font, background)
- process @import document to reduce the number of HTTP requests
- remove @charset directive
- query api with xpath like or class name syntax
- traverser api to transform the css and ast
- command line utility
Installation
install using Composer
PHP version >= 8.0
PHP version >= 5.6
Requirements
- PHP version >= 8.0 on master branch.
- PHP version >= 5.6 supported in this branch
- mbstring extension
Usage:
PHP Code
Result
Parse the css file and generate the AST
Load the AST and generate css code
Sourcemap generation
The CSS Query API
Example: get all background and background-image declarations that contain an image url
result
Example: Extract Font-src declaration
CSS source
PHP source
result
render optimized css
result
CSS Nesting
render CSS nesting
result
convert nesting CSS to older representation
result
The Traverser Api
The traverser will iterate over all the nodes and process them with the callbacks provided. It will return a new tree Example using ast
Example using an Element instance
Build a CSS Document
output
output
output
output
output
Adding existing css
Performance
Utility methods
The renderer class provides utility methods to format css data
Manual parsing and rendering
parsing and rendering ast is 3x faster than parsing an element.
Parser Options
- flatten_import: process @import directive and import the content into the css document. default to false.
- allow_duplicate_rules: allow duplicated rules. By default, duplicate rules except @font-face are merged
- allow_duplicate_declarations: allow duplicated declarations in the same rule.
- capture_errors: silently capture parse error if true, otherwise throw a parse exception. Default to true
Renderer Options
- remove_comments: remove comments.
- preserve_license: preserve comments starting with '/*!'
- compress: minify output, will also remove comments
- remove_empty_nodes: do not render empty css nodes
- compute_shorthand: compute shorthand declaration
- charset: preserve @charset. default to false
- glue: the line separator character. default to '\n'
- indent: character used to pad lines in css, default to a space character
- convert_color: convert colors to a format between hex, hsl, rgb, hwb and device-cmyk
- css_level: produce CSS color level 3 or 4. default to 4
- allow_duplicate_declarations: allow duplicate declarations.
- legacy_rendering: convert nesting css. default false
Command line utility
the command line utility is located at './cli/css-parser'
Minify inline css
Minify css file
Dump ast
The full documentation can be found here
Thanks to Jetbrains for providing a free PhpStorm license
This was originally a PHP port of https://github.com/reworkcss/css
All versions of css with dependencies
axy/sourcemap Version ^0.1.5
ext-json Version *
ext-mbstring Version *
opis/closure Version ^3.6