first commit

This commit is contained in:
Llewellyn van der Merwe 2023-04-15 16:58:37 +02:00
commit 297ff0a054
Signed by: Llewellyn
GPG Key ID: A9201372263741E7
38 changed files with 6001 additions and 0 deletions

213
README.md Normal file
View File

@ -0,0 +1,213 @@
```
███████╗██╗ ██╗██████╗ ███████╗██████╗
██╔════╝██║ ██║██╔══██╗██╔════╝██╔══██╗
███████╗██║ ██║██████╔╝█████╗ ██████╔╝
╚════██║██║ ██║██╔═══╝ ██╔══╝ ██╔══██╗
███████║╚██████╔╝██║ ███████╗██║ ██║
╚══════╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝
██████╗ ██████╗ ██╗ ██╗███████╗██████╗ ███████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗██╔════╝
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝███████╗
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗╚════██║
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║███████║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝╚══════╝
```
### What is JCB Super Powers?
The Joomla Component Builder (JCB) Super Power features are designed to enhance JCB's functionality and streamline the development process. These Super Powers enable developers to efficiently manage and share their custom powers across multiple JCB instances through repositories hosted on [https://git.vdm.dev/[username]/[repository-name]](https://git.vdm.dev). JCB Super Powers are managed using a combination of layers, events, tasks, methods, switches, and algorithms, which work together to provide powerful customization and extensibility options. More details on JCB Super Powers can be found in the [Super Powers Documentation](https://git.vdm.dev/joomla/super-powers/wiki).
In summary, JCB Super Powers offer a flexible and efficient way to manage and share functionalities between JCB instances. By utilizing a sophisticated system of layers, events, tasks, methods, switches, and algorithms, developers can seamlessly integrate JCB core powers and their custom powers. For more information on how to work with JCB Super Powers, refer to the [Super Powers User Guide](https://git.vdm.dev/joomla/super-powers/wiki).
### What can I find here?
This repository contains an index (see below) of all the approved powers within the JCB GUI. During the compilation of a component, these powers are automatically added to the repository, ensuring a well-organized and accessible collection of functionalities.
# Index of powers
- **Namespace**: [VDM\Minify](#vdm-minify)
- **class Css** | [Details](src/70530246-2903-4c02-af9a-61182e4d97b8) | [Code](src/70530246-2903-4c02-af9a-61182e4d97b8/code.php) | [Settings](src/70530246-2903-4c02-af9a-61182e4d97b8/settings.json) | [70530246-2903-4c02-af9a-61182e4d97b8](src/70530246-2903-4c02-af9a-61182e4d97b8)
- **class JavaScript** | [Details](src/ef6438c4-76db-4aa1-bb15-bc97583bcd2e) | [Code](src/ef6438c4-76db-4aa1-bb15-bc97583bcd2e/code.php) | [Settings](src/ef6438c4-76db-4aa1-bb15-bc97583bcd2e/settings.json) | [ef6438c4-76db-4aa1-bb15-bc97583bcd2e](src/ef6438c4-76db-4aa1-bb15-bc97583bcd2e)
- **Namespace**: [VDM\Minify\Abstraction](#vdm-minify-abstraction)
- **abstract class Minify** | [Details](src/d2b8599a-d5ce-49b1-b992-764bb7d55137) | [Code](src/d2b8599a-d5ce-49b1-b992-764bb7d55137/code.php) | [Settings](src/d2b8599a-d5ce-49b1-b992-764bb7d55137/settings.json) | [d2b8599a-d5ce-49b1-b992-764bb7d55137](src/d2b8599a-d5ce-49b1-b992-764bb7d55137)
- **Namespace**: [VDM\Minify\Path](#vdm-minify-path)
- **class Converter** | [Details](src/39f8957f-cc73-4da5-8b60-6cf25d4ab058) | [Code](src/39f8957f-cc73-4da5-8b60-6cf25d4ab058/code.php) | [Settings](src/39f8957f-cc73-4da5-8b60-6cf25d4ab058/settings.json) | [39f8957f-cc73-4da5-8b60-6cf25d4ab058](src/39f8957f-cc73-4da5-8b60-6cf25d4ab058)
- **Namespace**: [VDM\Minify\Path\Interfaces](#vdm-minify-path-interfaces)
- **interface ConverterInterface** | [Details](src/cc482882-5eef-476c-b835-7b0c5a17c0db) | [Code](src/cc482882-5eef-476c-b835-7b0c5a17c0db/code.php) | [Settings](src/cc482882-5eef-476c-b835-7b0c5a17c0db/settings.json) | [cc482882-5eef-476c-b835-7b0c5a17c0db](src/cc482882-5eef-476c-b835-7b0c5a17c0db)
- **Namespace**: [VDM\Joomla\Componentbuilder\Compiler\Utilities](#vdm-joomla-componentbuilder-compiler-utilities)
- **abstract class Minify** | [Details](src/b591855d-d106-4fe5-90ad-8e706f6267cf) | [Code](src/b591855d-d106-4fe5-90ad-8e706f6267cf/code.php) | [Settings](src/b591855d-d106-4fe5-90ad-8e706f6267cf/settings.json) | [b591855d-d106-4fe5-90ad-8e706f6267cf](src/b591855d-d106-4fe5-90ad-8e706f6267cf)
# Class Diagrams
## VDM Minify
> namespace VDM\Minify
```uml
@startuml
namespace VDM\Minify #Azure {
class Css #Gold {
# $maxImportSize
+ setMaxImportSize()
+ setImportExtensions()
# moveImportsToTop() : string
# combineImports() : string
# importFiles() : string
+ execute() : string
# move() : string
# shortenColors() : string
# shortenFontWeights() : string
# shortenZeroes() : string
# stripEmptyTags() : string
# stripComments()
# stripWhitespace() : string
# extractMath()
# extractCustomProperties()
# canImportBySize() : bool
# canImportByPath() : bool
# getPathConverter() : ConverterInterface
}
class JavaScript #Gold {
# $keywordsReserved
# $keywordsBefore
# $keywordsAfter
# $operatorsBefore
+ execute() : string
# stripComments()
# extractRegex()
# stripWhitespace() : string
# getOperatorsForRegex() : string[]
# getKeywordsForRegex() : string[]
# propertyNotation() : string
# shortenBools() : string
}
}
@enduml
```
## VDM Minify Abstraction
> namespace VDM\Minify\Abstraction
```uml
@startuml
namespace VDM\Minify\Abstraction #DarkCyan {
abstract Minify #Orange {
# $data
# $patterns
+ $extracted
+ __construct()
+ add() : static
+ addFile() : static
+ minify() : string
+ gzip() : string
+ cache() : CacheItemInterface
+ {abstract} execute() : string
# load() : string
# save()
# registerPattern()
# replace() : string
# executeReplacement() : string
# extractStrings()
# restoreExtractedData() : string
# canImportFile() : bool
# openFileForWriting() : resource
# writeToFile()
# {static} str_replace_first()
}
}
@enduml
```
## VDM Minify Path
> namespace VDM\Minify\Path
```uml
@startuml
namespace VDM\Minify\Path #DarkCyan {
class Converter #Gold {
# $from
# $to
+ __construct()
# normalize() : string
# shared() : string
+ convert() : string
# dirname() : string
}
}
@enduml
```
## VDM Minify Path Interfaces
> namespace VDM\Minify\Path\Interfaces
```uml
@startuml
namespace VDM\Minify\Path\Interfaces #Olive {
interface ConverterInterface #Lavender {
+ convert() : string
}
}
@enduml
```
## VDM Joomla Componentbuilder Compiler Utilities
> namespace VDM\Joomla\Componentbuilder\Compiler\Utilities
```uml
@startuml
namespace VDM\Joomla\Componentbuilder\Compiler\Utilities #LightGreen {
abstract Minify #Orange {
+ {static} js() : string
+ {static} css() : string
}
}
@enduml
```
---
```
██╗ ██████╗ ██████╗ ███╗ ███╗██╗ █████╗
██║██╔═══██╗██╔═══██╗████╗ ████║██║ ██╔══██╗
██║██║ ██║██║ ██║██╔████╔██║██║ ███████║
██ ██║██║ ██║██║ ██║██║╚██╔╝██║██║ ██╔══██║
╚█████╔╝╚██████╔╝╚██████╔╝██║ ╚═╝ ██║███████╗██║ ██║
╚════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
██████╗ ██████╗ ███╗ ███╗██████╗ ██████╗ ███╗ ██╗███████╗███╗ ██╗████████╗
██╔════╝██╔═══██╗████╗ ████║██╔══██╗██╔═══██╗████╗ ██║██╔════╝████╗ ██║╚══██╔══╝
██║ ██║ ██║██╔████╔██║██████╔╝██║ ██║██╔██╗ ██║█████╗ ██╔██╗ ██║ ██║
██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║ ██║██║╚██╗██║██╔══╝ ██║╚██╗██║ ██║
╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ╚██████╔╝██║ ╚████║███████╗██║ ╚████║ ██║
╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝╚═╝ ╚═══╝ ╚═╝
██████╗ ██╗ ██╗██╗██╗ ██████╗ ███████╗██████╗
██╔══██╗██║ ██║██║██║ ██╔══██╗██╔════╝██╔══██╗
██████╔╝██║ ██║██║██║ ██║ ██║█████╗ ██████╔╝
██╔══██╗██║ ██║██║██║ ██║ ██║██╔══╝ ██╔══██╗
██████╔╝╚██████╔╝██║███████╗██████╔╝███████╗██║ ██║
╚═════╝ ╚═════╝ ╚═╝╚══════╝╚═════╝ ╚══════╝╚═╝ ╚═╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,81 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# class Converter (Details)
> namespace: **VDM\Minify\Path**
```uml
@startuml
class Converter #Gold {
# $from
# $to
+ __construct(string $from, string $to, ...)
# normalize(string $path) : string
# shared(string $path1, string $path2) : string
+ convert(string $path) : string
# dirname(string $path) : string
}
note right of Converter::__construct
arguments:
string $from
string $to
string $root = ''
end note
note right of Converter::normalize
Normalize path.
return: string
end note
note right of Converter::shared
Figure out the shared path of 2 locations.
Example:
/home/forkcms/frontend/core/layout/images/img.gif
and
/home/forkcms/frontend/cache/minified_css
share
/home/forkcms/frontend
return: string
end note
note right of Converter::convert
Convert paths relative from 1 file to another.
E.g.
../images/img.gif relative to /home/forkcms/frontend/core/layout/css
should become:
../../core/layout/images/img.gif relative to
/home/forkcms/frontend/cache/minified_css
return: string
end note
note right of Converter::dirname
Attempt to get the directory name from a path.
return: string
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,207 @@
<?php
/**
* Convert paths relative from 1 file to another.
*
* E.g.
* ../../images/icon.jpg relative to /css/imports/icons.css
* becomes
* ../images/icon.jpg relative to /css/minified.css
*
* Please report bugs on https://github.com/matthiasmullie/path-converter/issues
*
* @author Matthias Mullie <pathconverter@mullie.eu>
* @copyright Copyright (c) 2015, Matthias Mullie. All rights reserved
* @license MIT License
*/
namespace VDM\Minify\Path;
use VDM\Minify\Path\Interfaces\ConverterInterface;
class Converter implements ConverterInterface
{
/**
* @var string
*/
protected $from;
/**
* @var string
*/
protected $to;
/**
* @param string $from The original base path (directory, not file!)
* @param string $to The new base path (directory, not file!)
* @param string $root Root directory (defaults to `getcwd`)
*/
public function __construct($from, $to, $root = '')
{
$shared = $this->shared($from, $to);
if ($shared === '') {
// when both paths have nothing in common, one of them is probably
// absolute while the other is relative
$root = $root ?: getcwd();
$from = strpos($from, $root) === 0 ? $from : preg_replace('/\/+/', '/', $root . '/' . $from);
$to = strpos($to, $root) === 0 ? $to : preg_replace('/\/+/', '/', $root . '/' . $to);
// or traveling the tree via `..`
// attempt to resolve path, or assume it's fine if it doesn't exist
$from = @realpath($from) ?: $from;
$to = @realpath($to) ?: $to;
}
$from = $this->dirname($from);
$to = $this->dirname($to);
$from = $this->normalize($from);
$to = $this->normalize($to);
$this->from = $from;
$this->to = $to;
}
/**
* Normalize path.
*
* @param string $path
*
* @return string
*/
protected function normalize($path)
{
// deal with different operating systems' directory structure
$path = rtrim(str_replace(DIRECTORY_SEPARATOR, '/', $path), '/');
// remove leading current directory.
if (substr($path, 0, 2) === './') {
$path = substr($path, 2);
}
// remove references to current directory in the path.
$path = str_replace('/./', '/', $path);
/*
* Example:
* /home/forkcms/frontend/cache/compiled_templates/../../core/layout/css/../images/img.gif
* to
* /home/forkcms/frontend/core/layout/images/img.gif
*/
do {
$path = preg_replace('/[^\/]+(?<!\.\.)\/\.\.\//', '', $path, -1, $count);
} while ($count);
return $path;
}
/**
* Figure out the shared path of 2 locations.
*
* Example:
* /home/forkcms/frontend/core/layout/images/img.gif
* and
* /home/forkcms/frontend/cache/minified_css
* share
* /home/forkcms/frontend
*
* @param string $path1
* @param string $path2
*
* @return string
*/
protected function shared($path1, $path2)
{
// $path could theoretically be empty (e.g. no path is given), in which
// case it shouldn't expand to array(''), which would compare to one's
// root /
$path1 = $path1 ? explode('/', $path1) : [];
$path2 = $path2 ? explode('/', $path2) : [];
$shared = [];
// compare paths & strip identical ancestors
foreach ($path1 as $i => $chunk) {
if (isset($path2[$i]) && $path1[$i] == $path2[$i]) {
$shared[] = $chunk;
} else {
break;
}
}
return implode('/', $shared);
}
/**
* Convert paths relative from 1 file to another.
*
* E.g.
* ../images/img.gif relative to /home/forkcms/frontend/core/layout/css
* should become:
* ../../core/layout/images/img.gif relative to
* /home/forkcms/frontend/cache/minified_css
*
* @param string $path The relative path that needs to be converted
*
* @return string The new relative path
*/
public function convert($path)
{
// quit early if conversion makes no sense
if ($this->from === $this->to) {
return $path;
}
$path = $this->normalize($path);
// if we're not dealing with a relative path, just return absolute
if (strpos($path, '/') === 0) {
return $path;
}
// normalize paths
$path = $this->normalize($this->from . '/' . $path);
// strip shared ancestor paths
$shared = $this->shared($path, $this->to);
$path = mb_substr($path, mb_strlen($shared));
$to = mb_substr($this->to, mb_strlen($shared));
// add .. for every directory that needs to be traversed to new path
$to = str_repeat('../', count(array_filter(explode('/', $to))));
return $to . ltrim($path, '/');
}
/**
* Attempt to get the directory name from a path.
*
* @param string $path
*
* @return string
*/
protected function dirname($path)
{
if (@is_file($path)) {
return dirname($path);
}
if (@is_dir($path)) {
return rtrim($path, '/');
}
// no known file/dir, start making assumptions
// ends in / = dir
if (mb_substr($path, -1) === '/') {
return rtrim($path, '/');
}
// has a dot in the name, likely a file
if (preg_match('/.*\..*$/', basename($path)) !== 0) {
return dirname($path);
}
// you're on your own here!
return $path;
}
}

View File

@ -0,0 +1,183 @@
/**
* @var string
*/
protected $from;
/**
* @var string
*/
protected $to;
/**
* @param string $from The original base path (directory, not file!)
* @param string $to The new base path (directory, not file!)
* @param string $root Root directory (defaults to `getcwd`)
*/
public function __construct($from, $to, $root = '')
{
$shared = $this->shared($from, $to);
if ($shared === '') {
// when both paths have nothing in common, one of them is probably
// absolute while the other is relative
$root = $root ?: getcwd();
$from = strpos($from, $root) === 0 ? $from : preg_replace('/\/+/', '/', $root . '/' . $from);
$to = strpos($to, $root) === 0 ? $to : preg_replace('/\/+/', '/', $root . '/' . $to);
// or traveling the tree via `..`
// attempt to resolve path, or assume it's fine if it doesn't exist
$from = @realpath($from) ?: $from;
$to = @realpath($to) ?: $to;
}
$from = $this->dirname($from);
$to = $this->dirname($to);
$from = $this->normalize($from);
$to = $this->normalize($to);
$this->from = $from;
$this->to = $to;
}
/**
* Normalize path.
*
* @param string $path
*
* @return string
*/
protected function normalize($path)
{
// deal with different operating systems' directory structure
$path = rtrim(str_replace(DIRECTORY_SEPARATOR, '/', $path), '/');
// remove leading current directory.
if (substr($path, 0, 2) === './') {
$path = substr($path, 2);
}
// remove references to current directory in the path.
$path = str_replace('/./', '/', $path);
/*
* Example:
* /home/forkcms/frontend/cache/compiled_templates/../../core/layout/css/../images/img.gif
* to
* /home/forkcms/frontend/core/layout/images/img.gif
*/
do {
$path = preg_replace('/[^\/]+(?<!\.\.)\/\.\.\//', '', $path, -1, $count);
} while ($count);
return $path;
}
/**
* Figure out the shared path of 2 locations.
*
* Example:
* /home/forkcms/frontend/core/layout/images/img.gif
* and
* /home/forkcms/frontend/cache/minified_css
* share
* /home/forkcms/frontend
*
* @param string $path1
* @param string $path2
*
* @return string
*/
protected function shared($path1, $path2)
{
// $path could theoretically be empty (e.g. no path is given), in which
// case it shouldn't expand to array(''), which would compare to one's
// root /
$path1 = $path1 ? explode('/', $path1) : [];
$path2 = $path2 ? explode('/', $path2) : [];
$shared = [];
// compare paths & strip identical ancestors
foreach ($path1 as $i => $chunk) {
if (isset($path2[$i]) && $path1[$i] == $path2[$i]) {
$shared[] = $chunk;
} else {
break;
}
}
return implode('/', $shared);
}
/**
* Convert paths relative from 1 file to another.
*
* E.g.
* ../images/img.gif relative to /home/forkcms/frontend/core/layout/css
* should become:
* ../../core/layout/images/img.gif relative to
* /home/forkcms/frontend/cache/minified_css
*
* @param string $path The relative path that needs to be converted
*
* @return string The new relative path
*/
public function convert($path)
{
// quit early if conversion makes no sense
if ($this->from === $this->to) {
return $path;
}
$path = $this->normalize($path);
// if we're not dealing with a relative path, just return absolute
if (strpos($path, '/') === 0) {
return $path;
}
// normalize paths
$path = $this->normalize($this->from . '/' . $path);
// strip shared ancestor paths
$shared = $this->shared($path, $this->to);
$path = mb_substr($path, mb_strlen($shared));
$to = mb_substr($this->to, mb_strlen($shared));
// add .. for every directory that needs to be traversed to new path
$to = str_repeat('../', count(array_filter(explode('/', $to))));
return $to . ltrim($path, '/');
}
/**
* Attempt to get the directory name from a path.
*
* @param string $path
*
* @return string
*/
protected function dirname($path)
{
if (@is_file($path)) {
return dirname($path);
}
if (@is_dir($path)) {
return rtrim($path, '/');
}
// no known file/dir, start making assumptions
// ends in / = dir
if (mb_substr($path, -1) === '/') {
return rtrim($path, '/');
}
// has a dot in the name, likely a file
if (preg_match('/.*\..*$/', basename($path)) !== 0) {
return dirname($path);
}
// you're on your own here!
return $path;
}

View File

@ -0,0 +1,20 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "0",
"guid": "39f8957f-cc73-4da5-8b60-6cf25d4ab058",
"implements": [
"cc482882-5eef-476c-b835-7b0c5a17c0db"
],
"load_selection": null,
"name": "Converter",
"power_version": "1.1.3",
"system_name": "Path.Converter",
"type": "class",
"use_selection": null,
"namespace": "VDM\\Minify\\Path.Converter",
"description": "",
"licensing_template": "\/**\r\n * Convert paths relative from 1 file to another.\r\n *\r\n * E.g.\r\n * ..\/..\/images\/icon.jpg relative to \/css\/imports\/icons.css\r\n * becomes\r\n * ..\/images\/icon.jpg relative to \/css\/minified.css\r\n *\r\n * Please report bugs on https:\/\/github.com\/matthiasmullie\/path-converter\/issues\r\n *\r\n * @author Matthias Mullie <pathconverter@mullie.eu>\r\n * @copyright Copyright (c) 2015, Matthias Mullie. All rights reserved\r\n * @license MIT License\r\n *\/",
"head": "",
"composer": ""
}

View File

@ -0,0 +1,21 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
> Error adding class diagram
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,25 @@
<?php
/**
* IO Exception.
*
* Please report bugs on https://github.com/matthiasmullie/minify/issues
*
* @author Matthias Mullie <minify@mullie.eu>
* @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved
* @license MIT License
*/
namespace VDM\Minify\Exceptions;
use VDM\Minify\Abstraction\BasicException;
/**
* IO Exception Class.
*
* @author Matthias Mullie
*/
class IOException extends BasicException
{
}

View File

@ -0,0 +1 @@
###CODEPOWER###

View File

@ -0,0 +1,18 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "47448ada-54df-45f3-b05d-1c66c584b1bd",
"guid": "44b4a9cf-62e6-48af-ab30-5b3d2715728e",
"implements": null,
"load_selection": null,
"name": "IOException",
"power_version": "1.0.0",
"system_name": "Minify.Exceptions.IOException",
"type": "class",
"use_selection": null,
"namespace": "VDM\\Minify\\Exceptions.IOException",
"description": "\/**\r\n * IO Exception Class.\r\n *\r\n * @author Matthias Mullie \r\n *\/",
"licensing_template": "\/**\r\n * IO Exception.\r\n *\r\n * Please report bugs on https:\/\/github.com\/matthiasmullie\/minify\/issues\r\n *\r\n * @author Matthias Mullie <minify@mullie.eu>\r\n * @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved\r\n * @license MIT License\r\n *\/",
"head": "",
"composer": ""
}

View File

@ -0,0 +1,21 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
> Error adding class diagram
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,26 @@
<?php
/**
* Basic exception.
*
* Please report bugs on https://github.com/matthiasmullie/minify/issues
*
* @author Matthias Mullie <minify@mullie.eu>
* @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved
* @license MIT License
*/
namespace VDM\Minify\Abstraction;
/**
* Basic exception.
*
* Please report bugs on https://github.com/matthiasmullie/minify/issues
*
* @author Matthias Mullie
* @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved
* @license MIT License
*/
abstract class BasicException extends \Exception
{
}

View File

@ -0,0 +1 @@
###CODEPOWER###

View File

@ -0,0 +1,19 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "-1",
"guid": "47448ada-54df-45f3-b05d-1c66c584b1bd",
"implements": null,
"load_selection": null,
"name": "BasicException",
"power_version": "1.0.0",
"system_name": "Minify.Abstraction.BasicException",
"type": "abstract class",
"use_selection": null,
"namespace": "VDM\\Minify\\Abstraction.BasicException",
"description": "\/**\r\n * Basic exception.\r\n *\r\n * Please report bugs on https:\/\/github.com\/matthiasmullie\/minify\/issues\r\n *\r\n * @author Matthias Mullie \r\n * @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved\r\n * @license MIT License\r\n *\/",
"extends_custom": "\\Exception",
"licensing_template": "\/**\r\n * Basic exception.\r\n *\r\n * Please report bugs on https:\/\/github.com\/matthiasmullie\/minify\/issues\r\n *\r\n * @author Matthias Mullie <minify@mullie.eu>\r\n * @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved\r\n * @license MIT License\r\n *\/",
"head": "",
"composer": ""
}

View File

@ -0,0 +1,174 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# class Css (Details)
> namespace: **VDM\Minify**
```uml
@startuml
class Css #Gold {
# $maxImportSize
+ setMaxImportSize(int $size)
+ setImportExtensions(array $extensions)
# moveImportsToTop(string $content) : string
# combineImports(string $source, string $content, ...) : string
# importFiles(string $source, string $content) : string
+ execute(string[optional] $path = null, string[] $parents = []) : string
# move(ConverterInterface $converter, string $content) : string
# shortenColors(string $content) : string
# shortenFontWeights(string $content) : string
# shortenZeroes(string $content) : string
# stripEmptyTags(string $content) : string
# stripComments()
# stripWhitespace(string $content) : string
# extractMath()
# extractCustomProperties()
# canImportBySize(string $path) : bool
# canImportByPath(string $path) : bool
# getPathConverter(string $source, string $target) : ConverterInterface
}
note right of Css::setMaxImportSize
Set the maximum size if files to be imported.
Files larger than this size (in kB) will not be imported into the CSS.
Importing files into the CSS as data-uri will save you some connections,
but we should only import relatively small decorative images so that our
CSS file doesn't get too bulky.
end note
note left of Css::setImportExtensions
Set the type of extensions to be imported into the CSS (to save network
connections).
Keys of the array should be the file extensions & respective values
should be the data type.
end note
note right of Css::moveImportsToTop
Move any import statements to the top.
return: string
end note
note left of Css::combineImports
Combine CSS from import statements.
Import statements will be loaded and their content merged into the original
file, to save HTTP requests.
return: string
arguments:
string $source
string $content
string[] $parents
end note
note right of Css::importFiles
Import files into the CSS, base64-ized.
original file, to save HTTP requests.
return: string
end note
note left of Css::execute
Minify the data.
Perform CSS optimizations.
return: string
end note
note right of Css::move
Moving a css file should update all relative urls.
Relative references (e.g. ../images/image.gif) in a certain css file,
will have to be updated when a file is being saved at another location
(e.g. ../../images/image.gif, if the new CSS file is 1 folder deeper).
return: string
end note
note left of Css::shortenColors
Shorthand hex color codes.
#FF0000 -> #F00.
return: string
end note
note right of Css::shortenFontWeights
Shorten CSS font weights.
return: string
end note
note left of Css::shortenZeroes
Shorthand 0 values to plain 0, instead of e.g. -0em.
return: string
end note
note right of Css::stripEmptyTags
Strip empty tags from source code.
return: string
end note
note left of Css::stripComments
Strip comments from source code.
end note
note right of Css::stripWhitespace
Strip whitespace.
return: string
end note
note left of Css::extractMath
Replace all occurrences of functions that may contain math, where
whitespace around operators needs to be preserved (e.g. calc, clamp).
end note
note right of Css::extractCustomProperties
Replace custom properties, whose values may be used in scenarios where
we wouldn't want them to be minified (e.g. inside calc).
end note
note left of Css::canImportBySize
Check if file is small enough to be imported.
return: bool
end note
note right of Css::canImportByPath
Check if file a file can be imported, going by the path.
return: bool
end note
note left of Css::getPathConverter
Return a converter to update relative paths to be relative to the new
destination.
return: ConverterInterface
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,754 @@
<?php
/**
* CSS Minifier.
*
* Please report bugs on https://github.com/matthiasmullie/minify/issues
*
* @author Matthias Mullie <minify@mullie.eu>
* @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved
* @license MIT License
*/
namespace VDM\Minify;
use VDM\Minify\Exceptions\FileImportException;
use VDM\Minify\Path\Converter;
use VDM\Minify\Path\Interfaces\ConverterInterface;
use VDM\Minify\Abstraction\Minify;
/**
* CSS minifier.
*
* Please report bugs on https://github.com/matthiasmullie/minify/issues
*
* @author Matthias Mullie
* @author Tijs Verkoyen
* @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved
* @license MIT License
*/
class Css extends Minify
{
/**
* @var int maximum inport size in kB
*/
protected $maxImportSize = 5;
/**
* @var string[] valid import extensions
*/
protected $importExtensions = array(
'gif' => 'data:image/gif',
'png' => 'data:image/png',
'jpe' => 'data:image/jpeg',
'jpg' => 'data:image/jpeg',
'jpeg' => 'data:image/jpeg',
'svg' => 'data:image/svg+xml',
'woff' => 'data:application/x-font-woff',
'woff2' => 'data:application/x-font-woff2',
'avif' => 'data:image/avif',
'apng' => 'data:image/apng',
'webp' => 'data:image/webp',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'xbm' => 'image/x-xbitmap',
);
/**
* Set the maximum size if files to be imported.
*
* Files larger than this size (in kB) will not be imported into the CSS.
* Importing files into the CSS as data-uri will save you some connections,
* but we should only import relatively small decorative images so that our
* CSS file doesn't get too bulky.
*
* @param int $size Size in kB
*/
public function setMaxImportSize($size)
{
$this->maxImportSize = $size;
}
/**
* Set the type of extensions to be imported into the CSS (to save network
* connections).
* Keys of the array should be the file extensions & respective values
* should be the data type.
*
* @param string[] $extensions Array of file extensions
*/
public function setImportExtensions(array $extensions)
{
$this->importExtensions = $extensions;
}
/**
* Move any import statements to the top.
*
* @param string $content Nearly finished CSS content
*
* @return string
*/
protected function moveImportsToTop($content)
{
if (preg_match_all('/(;?)(@import (?<url>url\()?(?P<quotes>["\']?).+?(?P=quotes)(?(url)\)));?/', $content, $matches)) {
// remove from content
foreach ($matches[0] as $import) {
$content = str_replace($import, '', $content);
}
// add to top
$content = implode(';', $matches[2]) . ';' . trim($content, ';');
}
return $content;
}
/**
* Combine CSS from import statements.
*
* Import statements will be loaded and their content merged into the original
* file, to save HTTP requests.
*
* @param string $source The file to combine imports for
* @param string $content The CSS content to combine imports for
* @param string[] $parents Parent paths, for circular reference checks
*
* @return string
*
* @throws FileImportException
*/
protected function combineImports($source, $content, $parents)
{
$importRegexes = array(
// @import url(xxx)
'/
# import statement
@import
# whitespace
\s+
# open url()
url\(
# (optional) open path enclosure
(?P<quotes>["\']?)
# fetch path
(?P<path>.+?)
# (optional) close path enclosure
(?P=quotes)
# close url()
\)
# (optional) trailing whitespace
\s*
# (optional) media statement(s)
(?P<media>[^;]*)
# (optional) trailing whitespace
\s*
# (optional) closing semi-colon
;?
/ix',
// @import 'xxx'
'/
# import statement
@import
# whitespace
\s+
# open path enclosure
(?P<quotes>["\'])
# fetch path
(?P<path>.+?)
# close path enclosure
(?P=quotes)
# (optional) trailing whitespace
\s*
# (optional) media statement(s)
(?P<media>[^;]*)
# (optional) trailing whitespace
\s*
# (optional) closing semi-colon
;?
/ix',
);
// find all relative imports in css
$matches = [];
foreach ($importRegexes as $importRegex) {
if (preg_match_all($importRegex, $content, $regexMatches, PREG_SET_ORDER)) {
$matches = [...$matches, ...$regexMatches];
}
}
$search = [];
$replace = [];
// loop the matches
foreach ($matches as $match) {
// get the path for the file that will be imported
$importPath = dirname($source) . '/' . $match['path'];
// only replace the import with the content if we can grab the
// content of the file
if (!$this->canImportByPath($match['path']) || !$this->canImportFile($importPath)) {
continue;
}
// check if current file was not imported previously in the same
// import chain.
if (in_array($importPath, $parents)) {
throw new FileImportException('Failed to import file "' . $importPath . '": circular reference detected.');
}
// grab referenced file & minify it (which may include importing
// yet other @import statements recursively)
$minifier = new self($importPath);
$minifier->setMaxImportSize($this->maxImportSize);
$minifier->setImportExtensions($this->importExtensions);
$importContent = $minifier->execute($source, $parents);
// check if this is only valid for certain media
if (!empty($match['media'])) {
$importContent = '@media ' . $match['media'] . '{' . $importContent . '}';
}
// add to replacement array
$search[] = $match[0];
$replace[] = $importContent;
}
// replace the import statements
return str_replace($search, $replace, $content);
}
/**
* Import files into the CSS, base64-ized.
*
* @url(image.jpg) images will be loaded and their content merged into the
* original file, to save HTTP requests.
*
* @param string $source The file to import files for
* @param string $content The CSS content to import files for
*
* @return string
*/
protected function importFiles($source, $content)
{
$regex = '/url\((["\']?)(.+?)\\1\)/i';
if ($this->importExtensions && preg_match_all($regex, $content, $matches, PREG_SET_ORDER)) {
$search = [];
$replace = [];
// loop the matches
foreach ($matches as $match) {
$extension = substr(strrchr($match[2], '.'), 1);
if ($extension && !array_key_exists($extension, $this->importExtensions)) {
continue;
}
// get the path for the file that will be imported
$path = $match[2];
$path = dirname($source) . '/' . $path;
// only replace the import with the content if we're able to get
// the content of the file, and it's relatively small
if ($this->canImportFile($path) && $this->canImportBySize($path)) {
// grab content && base64-ize
$importContent = $this->load($path);
$importContent = base64_encode($importContent);
// build replacement
$search[] = $match[0];
$replace[] = 'url(' . $this->importExtensions[$extension] . ';base64,' . $importContent . ')';
}
}
// replace the import statements
$content = str_replace($search, $replace, $content);
}
return $content;
}
/**
* Minify the data.
* Perform CSS optimizations.
*
* @param string[optional] $path Path to write the data to
* @param string[] $parents Parent paths, for circular reference checks
*
* @return string The minified data
*/
public function execute($path = null, $parents = [])
{
$content = '';
// loop CSS data (raw data and files)
foreach ($this->data as $source => $css) {
/*
* Let's first take out strings & comments, since we can't just
* remove whitespace anywhere. If whitespace occurs inside a string,
* we should leave it alone. E.g.:
* p { content: "a test" }
*/
$this->extractStrings();
$this->stripComments();
$this->extractMath();
$this->extractCustomProperties();
$css = $this->replace($css);
$css = $this->stripWhitespace($css);
$css = $this->shortenColors($css);
$css = $this->shortenZeroes($css);
$css = $this->shortenFontWeights($css);
$css = $this->stripEmptyTags($css);
// restore the string we've extracted earlier
$css = $this->restoreExtractedData($css);
$source = is_int($source) ? '' : $source;
$parents = $source ? array_merge($parents, array($source)) : $parents;
$css = $this->combineImports($source, $css, $parents);
$css = $this->importFiles($source, $css);
/*
* If we'll save to a new path, we'll have to fix the relative paths
* to be relative no longer to the source file, but to the new path.
* If we don't write to a file, fall back to same path so no
* conversion happens (because we still want it to go through most
* of the move code, which also addresses url() & @import syntax...)
*/
$converter = $this->getPathConverter($source, $path ?: $source);
$css = $this->move($converter, $css);
// combine css
$content .= $css;
}
$content = $this->moveImportsToTop($content);
return $content;
}
/**
* Moving a css file should update all relative urls.
* Relative references (e.g. ../images/image.gif) in a certain css file,
* will have to be updated when a file is being saved at another location
* (e.g. ../../images/image.gif, if the new CSS file is 1 folder deeper).
*
* @param ConverterInterface $converter Relative path converter
* @param string $content The CSS content to update relative urls for
*
* @return string
*/
protected function move(ConverterInterface $converter, $content)
{
/*
* Relative path references will usually be enclosed by url(). @import
* is an exception, where url() is not necessary around the path (but is
* allowed).
* This *could* be 1 regular expression, where both regular expressions
* in this array are on different sides of a |. But we're using named
* patterns in both regexes, the same name on both regexes. This is only
* possible with a (?J) modifier, but that only works after a fairly
* recent PCRE version. That's why I'm doing 2 separate regular
* expressions & combining the matches after executing of both.
*/
$relativeRegexes = array(
// url(xxx)
'/
# open url()
url\(
\s*
# open path enclosure
(?P<quotes>["\'])?
# fetch path
(?P<path>.+?)
# close path enclosure
(?(quotes)(?P=quotes))
\s*
# close url()
\)
/ix',
// @import "xxx"
'/
# import statement
@import
# whitespace
\s+
# we don\'t have to check for @import url(), because the
# condition above will already catch these
# open path enclosure
(?P<quotes>["\'])
# fetch path
(?P<path>.+?)
# close path enclosure
(?P=quotes)
/ix',
);
// find all relative urls in css
$matches = [];
foreach ($relativeRegexes as $relativeRegex) {
if (preg_match_all($relativeRegex, $content, $regexMatches, PREG_SET_ORDER)) {
$matches = [...$matches, ...$regexMatches];
}
}
$search = [];
$replace = [];
// loop all urls
foreach ($matches as $match) {
// determine if it's a url() or an @import match
$type = (strpos($match[0], '@import') === 0 ? 'import' : 'url');
$url = $match['path'];
if ($this->canImportByPath($url)) {
// attempting to interpret GET-params makes no sense, so let's discard them for awhile
$params = strrchr($url, '?');
$url = $params ? substr($url, 0, -strlen($params)) : $url;
// fix relative url
$url = $converter->convert($url);
// now that the path has been converted, re-apply GET-params
$url .= $params;
}
/*
* Urls with control characters above 0x7e should be quoted.
* According to Mozilla's parser, whitespace is only allowed at the
* end of unquoted urls.
* Urls with `)` (as could happen with data: uris) should also be
* quoted to avoid being confused for the url() closing parentheses.
* And urls with a # have also been reported to cause issues.
* Urls with quotes inside should also remain escaped.
*
* @see https://developer.mozilla.org/nl/docs/Web/CSS/url#The_url()_functional_notation
* @see https://hg.mozilla.org/mozilla-central/rev/14abca4e7378
* @see https://github.com/matthiasmullie/minify/issues/193
*/
$url = trim($url);
if (preg_match('/[\s\)\'"#\x{7f}-\x{9f}]/u', $url)) {
$url = $match['quotes'] . $url . $match['quotes'];
}
// build replacement
$search[] = $match[0];
if ($type === 'url') {
$replace[] = 'url(' . $url . ')';
} elseif ($type === 'import') {
$replace[] = '@import "' . $url . '"';
}
}
// replace urls
return str_replace($search, $replace, $content);
}
/**
* Shorthand hex color codes.
* #FF0000 -> #F00.
*
* @param string $content The CSS content to shorten the hex color codes for
*
* @return string
*/
protected function shortenColors($content)
{
$content = preg_replace('/(?<=[: ])#([0-9a-z])\\1([0-9a-z])\\2([0-9a-z])\\3(?:([0-9a-z])\\4)?(?=[; }])/i', '#$1$2$3$4', $content);
// remove alpha channel if it's pointless...
$content = preg_replace('/(?<=[: ])#([0-9a-z]{6})ff?(?=[; }])/i', '#$1', $content);
$content = preg_replace('/(?<=[: ])#([0-9a-z]{3})f?(?=[; }])/i', '#$1', $content);
$colors = array(
// we can shorten some even more by replacing them with their color name
'#F0FFFF' => 'azure',
'#F5F5DC' => 'beige',
'#A52A2A' => 'brown',
'#FF7F50' => 'coral',
'#FFD700' => 'gold',
'#808080' => 'gray',
'#008000' => 'green',
'#4B0082' => 'indigo',
'#FFFFF0' => 'ivory',
'#F0E68C' => 'khaki',
'#FAF0E6' => 'linen',
'#800000' => 'maroon',
'#000080' => 'navy',
'#808000' => 'olive',
'#CD853F' => 'peru',
'#FFC0CB' => 'pink',
'#DDA0DD' => 'plum',
'#800080' => 'purple',
'#F00' => 'red',
'#FA8072' => 'salmon',
'#A0522D' => 'sienna',
'#C0C0C0' => 'silver',
'#FFFAFA' => 'snow',
'#D2B48C' => 'tan',
'#FF6347' => 'tomato',
'#EE82EE' => 'violet',
'#F5DEB3' => 'wheat',
// or the other way around
'WHITE' => '#fff',
'BLACK' => '#000',
);
return preg_replace_callback(
'/(?<=[: ])(' . implode('|', array_keys($colors)) . ')(?=[; }])/i',
fn($match) => $colors[strtoupper((string) $match[0])],
$content
);
}
/**
* Shorten CSS font weights.
*
* @param string $content The CSS content to shorten the font weights for
*
* @return string
*/
protected function shortenFontWeights($content)
{
$weights = array(
'normal' => 400,
'bold' => 700,
);
$callback = fn($match) => $match[1] . $weights[$match[2]];
return preg_replace_callback('/(font-weight\s*:\s*)(' . implode('|', array_keys($weights)) . ')(?=[;}])/', $callback, $content);
}
/**
* Shorthand 0 values to plain 0, instead of e.g. -0em.
*
* @param string $content The CSS content to shorten the zero values for
*
* @return string
*/
protected function shortenZeroes($content)
{
// we don't want to strip units in `calc()` expressions:
// `5px - 0px` is valid, but `5px - 0` is not
// `10px * 0` is valid (equates to 0), and so is `10 * 0px`, but
// `10 * 0` is invalid
// we've extracted calcs earlier, so we don't need to worry about this
// reusable bits of code throughout these regexes:
// before & after are used to make sure we don't match lose unintended
// 0-like values (e.g. in #000, or in http://url/1.0)
// units can be stripped from 0 values, or used to recognize non 0
// values (where wa may be able to strip a .0 suffix)
$before = '(?<=[:(, ])';
$after = '(?=[ ,);}])';
$units = '(em|ex|%|px|cm|mm|in|pt|pc|ch|rem|vh|vw|vmin|vmax|vm)';
// strip units after zeroes (0px -> 0)
// NOTE: it should be safe to remove all units for a 0 value, but in
// practice, Webkit (especially Safari) seems to stumble over at least
// 0%, potentially other units as well. Only stripping 'px' for now.
// @see https://github.com/matthiasmullie/minify/issues/60
$content = preg_replace('/' . $before . '(-?0*(\.0+)?)(?<=0)px' . $after . '/', '\\1', $content);
// strip 0-digits (.0 -> 0)
$content = preg_replace('/' . $before . '\.0+' . $units . '?' . $after . '/', '0\\1', $content);
// strip trailing 0: 50.10 -> 50.1, 50.10px -> 50.1px
$content = preg_replace('/' . $before . '(-?[0-9]+\.[0-9]+)0+' . $units . '?' . $after . '/', '\\1\\2', $content);
// strip trailing 0: 50.00 -> 50, 50.00px -> 50px
$content = preg_replace('/' . $before . '(-?[0-9]+)\.0+' . $units . '?' . $after . '/', '\\1\\2', $content);
// strip leading 0: 0.1 -> .1, 01.1 -> 1.1
$content = preg_replace('/' . $before . '(-?)0+([0-9]*\.[0-9]+)' . $units . '?' . $after . '/', '\\1\\2\\3', $content);
// strip negative zeroes (-0 -> 0) & truncate zeroes (00 -> 0)
$content = preg_replace('/' . $before . '-?0+' . $units . '?' . $after . '/', '0\\1', $content);
// IE doesn't seem to understand a unitless flex-basis value (correct -
// it goes against the spec), so let's add it in again (make it `%`,
// which is only 1 char: 0%, 0px, 0 anything, it's all just the same)
// @see https://developer.mozilla.org/nl/docs/Web/CSS/flex
$content = preg_replace('/flex:([0-9]+\s[0-9]+\s)0([;\}])/', 'flex:${1}0%${2}', $content);
$content = preg_replace('/flex-basis:0([;\}])/', 'flex-basis:0%${1}', $content);
return $content;
}
/**
* Strip empty tags from source code.
*
* @param string $content
*
* @return string
*/
protected function stripEmptyTags($content)
{
$content = preg_replace('/(?<=^)[^\{\};]+\{\s*\}/', '', $content);
$content = preg_replace('/(?<=(\}|;))[^\{\};]+\{\s*\}/', '', $content);
return $content;
}
/**
* Strip comments from source code.
*/
protected function stripComments()
{
// PHP only supports $this inside anonymous functions since 5.4
$minifier = $this;
$callback = function ($match) use ($minifier) {
$count = count($minifier->extracted);
$placeholder = '/*' . $count . '*/';
$minifier->extracted[$placeholder] = $match[0];
return $placeholder;
};
$this->registerPattern('/\n?\/\*(!|.*?@license|.*?@preserve).*?\*\/\n?/s', $callback);
$this->registerPattern('/\/\*.*?\*\//s', '');
}
/**
* Strip whitespace.
*
* @param string $content The CSS content to strip the whitespace for
*
* @return string
*/
protected function stripWhitespace($content)
{
// remove leading & trailing whitespace
$content = preg_replace('/^\s*/m', '', $content);
$content = preg_replace('/\s*$/m', '', $content);
// replace newlines with a single space
$content = preg_replace('/\s+/', ' ', $content);
// remove whitespace around meta characters
// inspired by stackoverflow.com/questions/15195750/minify-compress-css-with-regex
$content = preg_replace('/\s*([\*$~^|]?+=|[{};,>~]|!important\b)\s*/', '$1', $content);
$content = preg_replace('/([\[(:>\+])\s+/', '$1', $content);
$content = preg_replace('/\s+([\]\)>\+])/', '$1', $content);
$content = preg_replace('/\s+(:)(?![^\}]*\{)/', '$1', $content);
// whitespace around + and - can only be stripped inside some pseudo-
// classes, like `:nth-child(3+2n)`
// not in things like `calc(3px + 2px)`, shorthands like `3px -2px`, or
// selectors like `div.weird- p`
$pseudos = array('nth-child', 'nth-last-child', 'nth-last-of-type', 'nth-of-type');
$content = preg_replace('/:(' . implode('|', $pseudos) . ')\(\s*([+-]?)\s*(.+?)\s*([+-]?)\s*(.*?)\s*\)/', ':$1($2$3$4$5)', $content);
// remove semicolon/whitespace followed by closing bracket
$content = str_replace(';}', '}', $content);
return trim($content);
}
/**
* Replace all occurrences of functions that may contain math, where
* whitespace around operators needs to be preserved (e.g. calc, clamp).
*/
protected function extractMath()
{
$functions = array('calc', 'clamp', 'min', 'max');
$pattern = '/\b(' . implode('|', $functions) . ')(\(.+?)(?=$|;|})/m';
// PHP only supports $this inside anonymous functions since 5.4
$minifier = $this;
$callback = function ($match) use ($minifier, $pattern, &$callback) {
$function = $match[1];
$length = strlen((string) $match[2]);
$expr = '';
$opened = 0;
// the regular expression for extracting math has 1 significant problem:
// it can't determine the correct closing parenthesis...
// instead, it'll match a larger portion of code to where it's certain that
// the calc() musts have ended, and we'll figure out which is the correct
// closing parenthesis here, by counting how many have opened
for ($i = 0; $i < $length; ++$i) {
$char = $match[2][$i];
$expr .= $char;
if ($char === '(') {
++$opened;
} elseif ($char === ')' && --$opened === 0) {
break;
}
}
// now that we've figured out where the calc() starts and ends, extract it
$count = count($minifier->extracted);
$placeholder = 'math(' . $count . ')';
$minifier->extracted[$placeholder] = $function . '(' . trim(substr($expr, 1, -1)) . ')';
// and since we've captured more code than required, we may have some leftover
// calc() in here too - go recursive on the remaining but of code to go figure
// that out and extract what is needed
$rest = $minifier->str_replace_first($function . $expr, '', $match[0]);
$rest = preg_replace_callback($pattern, $callback, $rest);
return $placeholder . $rest;
};
$this->registerPattern($pattern, $callback);
}
/**
* Replace custom properties, whose values may be used in scenarios where
* we wouldn't want them to be minified (e.g. inside calc).
*/
protected function extractCustomProperties()
{
// PHP only supports $this inside anonymous functions since 5.4
$minifier = $this;
$this->registerPattern(
'/(?<=^|[;}{])\s*(--[^:;{}"\'\s]+)\s*:([^;{}]+)/m',
function ($match) use ($minifier) {
$placeholder = '--custom-' . count($minifier->extracted) . ':0';
$minifier->extracted[$placeholder] = $match[1] . ':' . trim((string) $match[2]);
return $placeholder;
}
);
}
/**
* Check if file is small enough to be imported.
*
* @param string $path The path to the file
*
* @return bool
*/
protected function canImportBySize($path)
{
return ($size = @filesize($path)) && $size <= $this->maxImportSize * 1024;
}
/**
* Check if file a file can be imported, going by the path.
*
* @param string $path
*
* @return bool
*/
protected function canImportByPath($path)
{
return preg_match('/^(data:|https?:|\\/)/', $path) === 0;
}
/**
* Return a converter to update relative paths to be relative to the new
* destination.
*
* @param string $source
* @param string $target
*
* @return ConverterInterface
*/
protected function getPathConverter($source, $target)
{
return new Converter($source, $target);
}
}

View File

@ -0,0 +1,721 @@
/**
* @var int maximum inport size in kB
*/
protected $maxImportSize = 5;
/**
* @var string[] valid import extensions
*/
protected $importExtensions = array(
'gif' => 'data:image/gif',
'png' => 'data:image/png',
'jpe' => 'data:image/jpeg',
'jpg' => 'data:image/jpeg',
'jpeg' => 'data:image/jpeg',
'svg' => 'data:image/svg+xml',
'woff' => 'data:application/x-font-woff',
'woff2' => 'data:application/x-font-woff2',
'avif' => 'data:image/avif',
'apng' => 'data:image/apng',
'webp' => 'data:image/webp',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'xbm' => 'image/x-xbitmap',
);
/**
* Set the maximum size if files to be imported.
*
* Files larger than this size (in kB) will not be imported into the CSS.
* Importing files into the CSS as data-uri will save you some connections,
* but we should only import relatively small decorative images so that our
* CSS file doesn't get too bulky.
*
* @param int $size Size in kB
*/
public function setMaxImportSize($size)
{
$this->maxImportSize = $size;
}
/**
* Set the type of extensions to be imported into the CSS (to save network
* connections).
* Keys of the array should be the file extensions & respective values
* should be the data type.
*
* @param string[] $extensions Array of file extensions
*/
public function setImportExtensions(array $extensions)
{
$this->importExtensions = $extensions;
}
/**
* Move any import statements to the top.
*
* @param string $content Nearly finished CSS content
*
* @return string
*/
protected function moveImportsToTop($content)
{
if (preg_match_all('/(;?)(@import (?<url>url\()?(?P<quotes>["\']?).+?(?P=quotes)(?(url)\)));?/', $content, $matches)) {
// remove from content
foreach ($matches[0] as $import) {
$content = str_replace($import, '', $content);
}
// add to top
$content = implode(';', $matches[2]) . ';' . trim($content, ';');
}
return $content;
}
/**
* Combine CSS from import statements.
*
* Import statements will be loaded and their content merged into the original
* file, to save HTTP requests.
*
* @param string $source The file to combine imports for
* @param string $content The CSS content to combine imports for
* @param string[] $parents Parent paths, for circular reference checks
*
* @return string
*
* @throws FileImportException
*/
protected function combineImports($source, $content, $parents)
{
$importRegexes = array(
// @import url(xxx)
'/
# import statement
@import
# whitespace
\s+
# open url()
url\(
# (optional) open path enclosure
(?P<quotes>["\']?)
# fetch path
(?P<path>.+?)
# (optional) close path enclosure
(?P=quotes)
# close url()
\)
# (optional) trailing whitespace
\s*
# (optional) media statement(s)
(?P<media>[^;]*)
# (optional) trailing whitespace
\s*
# (optional) closing semi-colon
;?
/ix',
// @import 'xxx'
'/
# import statement
@import
# whitespace
\s+
# open path enclosure
(?P<quotes>["\'])
# fetch path
(?P<path>.+?)
# close path enclosure
(?P=quotes)
# (optional) trailing whitespace
\s*
# (optional) media statement(s)
(?P<media>[^;]*)
# (optional) trailing whitespace
\s*
# (optional) closing semi-colon
;?
/ix',
);
// find all relative imports in css
$matches = [];
foreach ($importRegexes as $importRegex) {
if (preg_match_all($importRegex, $content, $regexMatches, PREG_SET_ORDER)) {
$matches = [...$matches, ...$regexMatches];
}
}
$search = [];
$replace = [];
// loop the matches
foreach ($matches as $match) {
// get the path for the file that will be imported
$importPath = dirname($source) . '/' . $match['path'];
// only replace the import with the content if we can grab the
// content of the file
if (!$this->canImportByPath($match['path']) || !$this->canImportFile($importPath)) {
continue;
}
// check if current file was not imported previously in the same
// import chain.
if (in_array($importPath, $parents)) {
throw new FileImportException('Failed to import file "' . $importPath . '": circular reference detected.');
}
// grab referenced file & minify it (which may include importing
// yet other @import statements recursively)
$minifier = new self($importPath);
$minifier->setMaxImportSize($this->maxImportSize);
$minifier->setImportExtensions($this->importExtensions);
$importContent = $minifier->execute($source, $parents);
// check if this is only valid for certain media
if (!empty($match['media'])) {
$importContent = '@media ' . $match['media'] . '{' . $importContent . '}';
}
// add to replacement array
$search[] = $match[0];
$replace[] = $importContent;
}
// replace the import statements
return str_replace($search, $replace, $content);
}
/**
* Import files into the CSS, base64-ized.
*
* @url(image.jpg) images will be loaded and their content merged into the
* original file, to save HTTP requests.
*
* @param string $source The file to import files for
* @param string $content The CSS content to import files for
*
* @return string
*/
protected function importFiles($source, $content)
{
$regex = '/url\((["\']?)(.+?)\\1\)/i';
if ($this->importExtensions && preg_match_all($regex, $content, $matches, PREG_SET_ORDER)) {
$search = [];
$replace = [];
// loop the matches
foreach ($matches as $match) {
$extension = substr(strrchr($match[2], '.'), 1);
if ($extension && !array_key_exists($extension, $this->importExtensions)) {
continue;
}
// get the path for the file that will be imported
$path = $match[2];
$path = dirname($source) . '/' . $path;
// only replace the import with the content if we're able to get
// the content of the file, and it's relatively small
if ($this->canImportFile($path) && $this->canImportBySize($path)) {
// grab content && base64-ize
$importContent = $this->load($path);
$importContent = base64_encode($importContent);
// build replacement
$search[] = $match[0];
$replace[] = 'url(' . $this->importExtensions[$extension] . ';base64,' . $importContent . ')';
}
}
// replace the import statements
$content = str_replace($search, $replace, $content);
}
return $content;
}
/**
* Minify the data.
* Perform CSS optimizations.
*
* @param string[optional] $path Path to write the data to
* @param string[] $parents Parent paths, for circular reference checks
*
* @return string The minified data
*/
public function execute($path = null, $parents = [])
{
$content = '';
// loop CSS data (raw data and files)
foreach ($this->data as $source => $css) {
/*
* Let's first take out strings & comments, since we can't just
* remove whitespace anywhere. If whitespace occurs inside a string,
* we should leave it alone. E.g.:
* p { content: "a test" }
*/
$this->extractStrings();
$this->stripComments();
$this->extractMath();
$this->extractCustomProperties();
$css = $this->replace($css);
$css = $this->stripWhitespace($css);
$css = $this->shortenColors($css);
$css = $this->shortenZeroes($css);
$css = $this->shortenFontWeights($css);
$css = $this->stripEmptyTags($css);
// restore the string we've extracted earlier
$css = $this->restoreExtractedData($css);
$source = is_int($source) ? '' : $source;
$parents = $source ? array_merge($parents, array($source)) : $parents;
$css = $this->combineImports($source, $css, $parents);
$css = $this->importFiles($source, $css);
/*
* If we'll save to a new path, we'll have to fix the relative paths
* to be relative no longer to the source file, but to the new path.
* If we don't write to a file, fall back to same path so no
* conversion happens (because we still want it to go through most
* of the move code, which also addresses url() & @import syntax...)
*/
$converter = $this->getPathConverter($source, $path ?: $source);
$css = $this->move($converter, $css);
// combine css
$content .= $css;
}
$content = $this->moveImportsToTop($content);
return $content;
}
/**
* Moving a css file should update all relative urls.
* Relative references (e.g. ../images/image.gif) in a certain css file,
* will have to be updated when a file is being saved at another location
* (e.g. ../../images/image.gif, if the new CSS file is 1 folder deeper).
*
* @param ConverterInterface $converter Relative path converter
* @param string $content The CSS content to update relative urls for
*
* @return string
*/
protected function move(ConverterInterface $converter, $content)
{
/*
* Relative path references will usually be enclosed by url(). @import
* is an exception, where url() is not necessary around the path (but is
* allowed).
* This *could* be 1 regular expression, where both regular expressions
* in this array are on different sides of a |. But we're using named
* patterns in both regexes, the same name on both regexes. This is only
* possible with a (?J) modifier, but that only works after a fairly
* recent PCRE version. That's why I'm doing 2 separate regular
* expressions & combining the matches after executing of both.
*/
$relativeRegexes = array(
// url(xxx)
'/
# open url()
url\(
\s*
# open path enclosure
(?P<quotes>["\'])?
# fetch path
(?P<path>.+?)
# close path enclosure
(?(quotes)(?P=quotes))
\s*
# close url()
\)
/ix',
// @import "xxx"
'/
# import statement
@import
# whitespace
\s+
# we don\'t have to check for @import url(), because the
# condition above will already catch these
# open path enclosure
(?P<quotes>["\'])
# fetch path
(?P<path>.+?)
# close path enclosure
(?P=quotes)
/ix',
);
// find all relative urls in css
$matches = [];
foreach ($relativeRegexes as $relativeRegex) {
if (preg_match_all($relativeRegex, $content, $regexMatches, PREG_SET_ORDER)) {
$matches = [...$matches, ...$regexMatches];
}
}
$search = [];
$replace = [];
// loop all urls
foreach ($matches as $match) {
// determine if it's a url() or an @import match
$type = (strpos($match[0], '@import') === 0 ? 'import' : 'url');
$url = $match['path'];
if ($this->canImportByPath($url)) {
// attempting to interpret GET-params makes no sense, so let's discard them for awhile
$params = strrchr($url, '?');
$url = $params ? substr($url, 0, -strlen($params)) : $url;
// fix relative url
$url = $converter->convert($url);
// now that the path has been converted, re-apply GET-params
$url .= $params;
}
/*
* Urls with control characters above 0x7e should be quoted.
* According to Mozilla's parser, whitespace is only allowed at the
* end of unquoted urls.
* Urls with `)` (as could happen with data: uris) should also be
* quoted to avoid being confused for the url() closing parentheses.
* And urls with a # have also been reported to cause issues.
* Urls with quotes inside should also remain escaped.
*
* @see https://developer.mozilla.org/nl/docs/Web/CSS/url#The_url()_functional_notation
* @see https://hg.mozilla.org/mozilla-central/rev/14abca4e7378
* @see https://github.com/matthiasmullie/minify/issues/193
*/
$url = trim($url);
if (preg_match('/[\s\)\'"#\x{7f}-\x{9f}]/u', $url)) {
$url = $match['quotes'] . $url . $match['quotes'];
}
// build replacement
$search[] = $match[0];
if ($type === 'url') {
$replace[] = 'url(' . $url . ')';
} elseif ($type === 'import') {
$replace[] = '@import "' . $url . '"';
}
}
// replace urls
return str_replace($search, $replace, $content);
}
/**
* Shorthand hex color codes.
* #FF0000 -> #F00.
*
* @param string $content The CSS content to shorten the hex color codes for
*
* @return string
*/
protected function shortenColors($content)
{
$content = preg_replace('/(?<=[: ])#([0-9a-z])\\1([0-9a-z])\\2([0-9a-z])\\3(?:([0-9a-z])\\4)?(?=[; }])/i', '#$1$2$3$4', $content);
// remove alpha channel if it's pointless...
$content = preg_replace('/(?<=[: ])#([0-9a-z]{6})ff?(?=[; }])/i', '#$1', $content);
$content = preg_replace('/(?<=[: ])#([0-9a-z]{3})f?(?=[; }])/i', '#$1', $content);
$colors = array(
// we can shorten some even more by replacing them with their color name
'#F0FFFF' => 'azure',
'#F5F5DC' => 'beige',
'#A52A2A' => 'brown',
'#FF7F50' => 'coral',
'#FFD700' => 'gold',
'#808080' => 'gray',
'#008000' => 'green',
'#4B0082' => 'indigo',
'#FFFFF0' => 'ivory',
'#F0E68C' => 'khaki',
'#FAF0E6' => 'linen',
'#800000' => 'maroon',
'#000080' => 'navy',
'#808000' => 'olive',
'#CD853F' => 'peru',
'#FFC0CB' => 'pink',
'#DDA0DD' => 'plum',
'#800080' => 'purple',
'#F00' => 'red',
'#FA8072' => 'salmon',
'#A0522D' => 'sienna',
'#C0C0C0' => 'silver',
'#FFFAFA' => 'snow',
'#D2B48C' => 'tan',
'#FF6347' => 'tomato',
'#EE82EE' => 'violet',
'#F5DEB3' => 'wheat',
// or the other way around
'WHITE' => '#fff',
'BLACK' => '#000',
);
return preg_replace_callback(
'/(?<=[: ])(' . implode('|', array_keys($colors)) . ')(?=[; }])/i',
fn($match) => $colors[strtoupper((string) $match[0])],
$content
);
}
/**
* Shorten CSS font weights.
*
* @param string $content The CSS content to shorten the font weights for
*
* @return string
*/
protected function shortenFontWeights($content)
{
$weights = array(
'normal' => 400,
'bold' => 700,
);
$callback = fn($match) => $match[1] . $weights[$match[2]];
return preg_replace_callback('/(font-weight\s*:\s*)(' . implode('|', array_keys($weights)) . ')(?=[;}])/', $callback, $content);
}
/**
* Shorthand 0 values to plain 0, instead of e.g. -0em.
*
* @param string $content The CSS content to shorten the zero values for
*
* @return string
*/
protected function shortenZeroes($content)
{
// we don't want to strip units in `calc()` expressions:
// `5px - 0px` is valid, but `5px - 0` is not
// `10px * 0` is valid (equates to 0), and so is `10 * 0px`, but
// `10 * 0` is invalid
// we've extracted calcs earlier, so we don't need to worry about this
// reusable bits of code throughout these regexes:
// before & after are used to make sure we don't match lose unintended
// 0-like values (e.g. in #000, or in http://url/1.0)
// units can be stripped from 0 values, or used to recognize non 0
// values (where wa may be able to strip a .0 suffix)
$before = '(?<=[:(, ])';
$after = '(?=[ ,);}])';
$units = '(em|ex|%|px|cm|mm|in|pt|pc|ch|rem|vh|vw|vmin|vmax|vm)';
// strip units after zeroes (0px -> 0)
// NOTE: it should be safe to remove all units for a 0 value, but in
// practice, Webkit (especially Safari) seems to stumble over at least
// 0%, potentially other units as well. Only stripping 'px' for now.
// @see https://github.com/matthiasmullie/minify/issues/60
$content = preg_replace('/' . $before . '(-?0*(\.0+)?)(?<=0)px' . $after . '/', '\\1', $content);
// strip 0-digits (.0 -> 0)
$content = preg_replace('/' . $before . '\.0+' . $units . '?' . $after . '/', '0\\1', $content);
// strip trailing 0: 50.10 -> 50.1, 50.10px -> 50.1px
$content = preg_replace('/' . $before . '(-?[0-9]+\.[0-9]+)0+' . $units . '?' . $after . '/', '\\1\\2', $content);
// strip trailing 0: 50.00 -> 50, 50.00px -> 50px
$content = preg_replace('/' . $before . '(-?[0-9]+)\.0+' . $units . '?' . $after . '/', '\\1\\2', $content);
// strip leading 0: 0.1 -> .1, 01.1 -> 1.1
$content = preg_replace('/' . $before . '(-?)0+([0-9]*\.[0-9]+)' . $units . '?' . $after . '/', '\\1\\2\\3', $content);
// strip negative zeroes (-0 -> 0) & truncate zeroes (00 -> 0)
$content = preg_replace('/' . $before . '-?0+' . $units . '?' . $after . '/', '0\\1', $content);
// IE doesn't seem to understand a unitless flex-basis value (correct -
// it goes against the spec), so let's add it in again (make it `%`,
// which is only 1 char: 0%, 0px, 0 anything, it's all just the same)
// @see https://developer.mozilla.org/nl/docs/Web/CSS/flex
$content = preg_replace('/flex:([0-9]+\s[0-9]+\s)0([;\}])/', 'flex:${1}0%${2}', $content);
$content = preg_replace('/flex-basis:0([;\}])/', 'flex-basis:0%${1}', $content);
return $content;
}
/**
* Strip empty tags from source code.
*
* @param string $content
*
* @return string
*/
protected function stripEmptyTags($content)
{
$content = preg_replace('/(?<=^)[^\{\};]+\{\s*\}/', '', $content);
$content = preg_replace('/(?<=(\}|;))[^\{\};]+\{\s*\}/', '', $content);
return $content;
}
/**
* Strip comments from source code.
*/
protected function stripComments()
{
// PHP only supports $this inside anonymous functions since 5.4
$minifier = $this;
$callback = function ($match) use ($minifier) {
$count = count($minifier->extracted);
$placeholder = '/*' . $count . '*/';
$minifier->extracted[$placeholder] = $match[0];
return $placeholder;
};
$this->registerPattern('/\n?\/\*(!|.*?@license|.*?@preserve).*?\*\/\n?/s', $callback);
$this->registerPattern('/\/\*.*?\*\//s', '');
}
/**
* Strip whitespace.
*
* @param string $content The CSS content to strip the whitespace for
*
* @return string
*/
protected function stripWhitespace($content)
{
// remove leading & trailing whitespace
$content = preg_replace('/^\s*/m', '', $content);
$content = preg_replace('/\s*$/m', '', $content);
// replace newlines with a single space
$content = preg_replace('/\s+/', ' ', $content);
// remove whitespace around meta characters
// inspired by stackoverflow.com/questions/15195750/minify-compress-css-with-regex
$content = preg_replace('/\s*([\*$~^|]?+=|[{};,>~]|!important\b)\s*/', '$1', $content);
$content = preg_replace('/([\[(:>\+])\s+/', '$1', $content);
$content = preg_replace('/\s+([\]\)>\+])/', '$1', $content);
$content = preg_replace('/\s+(:)(?![^\}]*\{)/', '$1', $content);
// whitespace around + and - can only be stripped inside some pseudo-
// classes, like `:nth-child(3+2n)`
// not in things like `calc(3px + 2px)`, shorthands like `3px -2px`, or
// selectors like `div.weird- p`
$pseudos = array('nth-child', 'nth-last-child', 'nth-last-of-type', 'nth-of-type');
$content = preg_replace('/:(' . implode('|', $pseudos) . ')\(\s*([+-]?)\s*(.+?)\s*([+-]?)\s*(.*?)\s*\)/', ':$1($2$3$4$5)', $content);
// remove semicolon/whitespace followed by closing bracket
$content = str_replace(';}', '}', $content);
return trim($content);
}
/**
* Replace all occurrences of functions that may contain math, where
* whitespace around operators needs to be preserved (e.g. calc, clamp).
*/
protected function extractMath()
{
$functions = array('calc', 'clamp', 'min', 'max');
$pattern = '/\b(' . implode('|', $functions) . ')(\(.+?)(?=$|;|})/m';
// PHP only supports $this inside anonymous functions since 5.4
$minifier = $this;
$callback = function ($match) use ($minifier, $pattern, &$callback) {
$function = $match[1];
$length = strlen((string) $match[2]);
$expr = '';
$opened = 0;
// the regular expression for extracting math has 1 significant problem:
// it can't determine the correct closing parenthesis...
// instead, it'll match a larger portion of code to where it's certain that
// the calc() musts have ended, and we'll figure out which is the correct
// closing parenthesis here, by counting how many have opened
for ($i = 0; $i < $length; ++$i) {
$char = $match[2][$i];
$expr .= $char;
if ($char === '(') {
++$opened;
} elseif ($char === ')' && --$opened === 0) {
break;
}
}
// now that we've figured out where the calc() starts and ends, extract it
$count = count($minifier->extracted);
$placeholder = 'math(' . $count . ')';
$minifier->extracted[$placeholder] = $function . '(' . trim(substr($expr, 1, -1)) . ')';
// and since we've captured more code than required, we may have some leftover
// calc() in here too - go recursive on the remaining but of code to go figure
// that out and extract what is needed
$rest = $minifier->str_replace_first($function . $expr, '', $match[0]);
$rest = preg_replace_callback($pattern, $callback, $rest);
return $placeholder . $rest;
};
$this->registerPattern($pattern, $callback);
}
/**
* Replace custom properties, whose values may be used in scenarios where
* we wouldn't want them to be minified (e.g. inside calc).
*/
protected function extractCustomProperties()
{
// PHP only supports $this inside anonymous functions since 5.4
$minifier = $this;
$this->registerPattern(
'/(?<=^|[;}{])\s*(--[^:;{}"\'\s]+)\s*:([^;{}]+)/m',
function ($match) use ($minifier) {
$placeholder = '--custom-' . count($minifier->extracted) . ':0';
$minifier->extracted[$placeholder] = $match[1] . ':' . trim((string) $match[2]);
return $placeholder;
}
);
}
/**
* Check if file is small enough to be imported.
*
* @param string $path The path to the file
*
* @return bool
*/
protected function canImportBySize($path)
{
return ($size = @filesize($path)) && $size <= $this->maxImportSize * 1024;
}
/**
* Check if file a file can be imported, going by the path.
*
* @param string $path
*
* @return bool
*/
protected function canImportByPath($path)
{
return preg_match('/^(data:|https?:|\\/)/', $path) === 0;
}
/**
* Return a converter to update relative paths to be relative to the new
* destination.
*
* @param string $source
* @param string $target
*
* @return ConverterInterface
*/
protected function getPathConverter($source, $target)
{
return new Converter($source, $target);
}

View File

@ -0,0 +1,31 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "d2b8599a-d5ce-49b1-b992-764bb7d55137",
"guid": "70530246-2903-4c02-af9a-61182e4d97b8",
"implements": null,
"load_selection": null,
"name": "Css",
"power_version": "1.3.70",
"system_name": "Minify.Css",
"type": "class",
"use_selection": {
"use_selection0": {
"use": "b34dbbeb-89bd-4f01-8bbd-f7ba0fb6280b",
"as": "default"
},
"use_selection1": {
"use": "39f8957f-cc73-4da5-8b60-6cf25d4ab058",
"as": "default"
},
"use_selection2": {
"use": "cc482882-5eef-476c-b835-7b0c5a17c0db",
"as": "default"
}
},
"namespace": "VDM\\Minify\\Css",
"description": "\/**\r\n * CSS minifier.\r\n *\r\n * Please report bugs on https:\/\/github.com\/matthiasmullie\/minify\/issues\r\n *\r\n * @author Matthias Mullie \r\n * @author Tijs Verkoyen \r\n * @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved\r\n * @license MIT License\r\n *\/",
"licensing_template": "\/**\r\n * CSS Minifier.\r\n *\r\n * Please report bugs on https:\/\/github.com\/matthiasmullie\/minify\/issues\r\n *\r\n * @author Matthias Mullie <minify@mullie.eu>\r\n * @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved\r\n * @license MIT License\r\n *\/",
"head": "",
"composer": ""
}

View File

@ -0,0 +1,21 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
> Error adding class diagram
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,25 @@
<?php
/**
* File Import Exception.
*
* Please report bugs on https://github.com/matthiasmullie/minify/issues
*
* @author Matthias Mullie <minify@mullie.eu>
* @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved
* @license MIT License
*/
namespace VDM\Minify\Exceptions;
use VDM\Minify\Abstraction\BasicException;
/**
* File Import Exception Class.
*
* @author Matthias Mullie
*/
class FileImportException extends BasicException
{
}

View File

@ -0,0 +1 @@
###CODEPOWER###

View File

@ -0,0 +1,18 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "47448ada-54df-45f3-b05d-1c66c584b1bd",
"guid": "b34dbbeb-89bd-4f01-8bbd-f7ba0fb6280b",
"implements": null,
"load_selection": null,
"name": "FileImportException",
"power_version": "1.0.0",
"system_name": "Minify.Exceptions.FileImportException",
"type": "class",
"use_selection": null,
"namespace": "VDM\\Minify\\Exceptions.FileImportException",
"description": "\/**\r\n * File Import Exception Class.\r\n *\r\n * @author Matthias Mullie \r\n *\/",
"licensing_template": "\/**\r\n * File Import Exception.\r\n *\r\n * Please report bugs on https:\/\/github.com\/matthiasmullie\/minify\/issues\r\n *\r\n * @author Matthias Mullie <minify@mullie.eu>\r\n * @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved\r\n * @license MIT License\r\n *\/",
"head": "",
"composer": ""
}

View File

@ -0,0 +1,45 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# abstract class Minify (Details)
> namespace: **VDM\Joomla\Componentbuilder\Compiler\Utilities**
```uml
@startuml
abstract Minify #Orange {
+ {static} js(string $data) : string
+ {static} css(string $data) : string
}
note right of Minify::js
Minify JavaScript
since: 3.2.0
return: string
end note
note right of Minify::css
Minify Css
since: 3.2.0
return: string
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,91 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Utilities;
use VDM\Minify\Css;
use VDM\Minify\JavaScript;
/**
* Compiler Minifier
*
* @since 3.2.0
*/
abstract class Minify
{
/**
* Minify JavaScript Class
*
* @var JavaScript
* @since 3.2.0
*/
public static JavaScript $js;
/**
* Minify Css Class
*
* @var Css
* @since 3.2.0
*/
public static Css $css;
/**
* Minify JavaScript
*
* @param string $data
*
* @return string
* @since 3.2.0
*/
public static function js(string $data): string
{
// check if instance already set
if (empty(self::$js))
{
// set instanceof on JavaScript
self::$js = new JavaScript;
}
// add the data
self::$js->add($data);
// return minified
return self::$js->minify();
}
/**
* Minify Css
*
* @param string $data
*
* @return string
* @since 3.2.0
*/
public static function css(string $data): string
{
// check if instance already set
if (empty(self::$css))
{
// set instanceof on Css
self::$css = new Css;
}
// add the data
self::$css->add($data);
// return minified
return self::$css->minify();
}
}

View File

@ -0,0 +1,63 @@
/**
* Minify JavaScript Class
*
* @var JavaScript
* @since 3.2.0
*/
public static JavaScript $js;
/**
* Minify Css Class
*
* @var Css
* @since 3.2.0
*/
public static Css $css;
/**
* Minify JavaScript
*
* @param string $data
*
* @return string
* @since 3.2.0
*/
public static function js(string $data): string
{
// check if instance already set
if (empty(self::$js))
{
// set instanceof on JavaScript
self::$js = new JavaScript;
}
// add the data
self::$js->add($data);
// return minified
return self::$js->minify();
}
/**
* Minify Css
*
* @param string $data
*
* @return string
* @since 3.2.0
*/
public static function css(string $data): string
{
// check if instance already set
if (empty(self::$css))
{
// set instanceof on Css
self::$css = new Css;
}
// add the data
self::$css->add($data);
// return minified
return self::$css->minify();
}

View File

@ -0,0 +1,27 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "0",
"guid": "b591855d-d106-4fe5-90ad-8e706f6267cf",
"implements": null,
"load_selection": null,
"name": "Minify",
"power_version": "1.0.0",
"system_name": "JCB.Compiler.Utilities.Minify",
"type": "abstract class",
"use_selection": {
"use_selection0": {
"use": "70530246-2903-4c02-af9a-61182e4d97b8",
"as": "default"
},
"use_selection1": {
"use": "ef6438c4-76db-4aa1-bb15-bc97583bcd2e",
"as": "default"
}
},
"namespace": "VDM\\Joomla\\Componentbuilder.Compiler.Utilities.Minify",
"description": "Compiler Minifier\r\n\r\n@since 3.2.0",
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
"head": "",
"composer": ""
}

View File

@ -0,0 +1,36 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# interface ConverterInterface (Details)
> namespace: **VDM\Minify\Path\Interfaces**
```uml
@startuml
interface ConverterInterface #Lavender {
+ convert(string $path) : string
}
note right of ConverterInterface::convert
Convert file paths.
return: string
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,24 @@
<?php
/**
* Convert file paths.
*
* Please report bugs on https://github.com/matthiasmullie/path-converter/issues
*
* @author Matthias Mullie <pathconverter@mullie.eu>
* @copyright Copyright (c) 2015, Matthias Mullie. All rights reserved
* @license MIT License
*/
namespace VDM\Minify\Path\Interfaces;
interface ConverterInterface
{
/**
* Convert file paths.
*
* @param string $path The path to be converted
*
* @return string The new path
*/
public function convert($path);
}

View File

@ -0,0 +1,8 @@
/**
* Convert file paths.
*
* @param string $path The path to be converted
*
* @return string The new path
*/
public function convert($path);

View File

@ -0,0 +1,18 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "0",
"guid": "cc482882-5eef-476c-b835-7b0c5a17c0db",
"implements": null,
"load_selection": null,
"name": "ConverterInterface",
"power_version": "1.1.3",
"system_name": "Path.Interfaces.ConverterInterface",
"type": "interface",
"use_selection": null,
"namespace": "VDM\\Minify\\Path.Interfaces.ConverterInterface",
"description": "",
"licensing_template": "\/**\r\n * Convert file paths.\r\n *\r\n * Please report bugs on https:\/\/github.com\/matthiasmullie\/path-converter\/issues\r\n *\r\n * @author Matthias Mullie <pathconverter@mullie.eu>\r\n * @copyright Copyright (c) 2015, Matthias Mullie. All rights reserved\r\n * @license MIT License\r\n *\/",
"head": "",
"composer": ""
}

View File

@ -0,0 +1,177 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# abstract class Minify (Details)
> namespace: **VDM\Minify\Abstraction**
```uml
@startuml
abstract Minify #Orange {
# $data
# $patterns
+ $extracted
+ __construct($data = null)
+ add(string|string[] $data = null) : static
+ addFile(string|string[] $data = null) : static
+ minify(string[optional] $path = null) : string
+ gzip(string[optional] $path = null, int[optional] $level = 9) : string
+ cache(CacheItemInterface $item) : CacheItemInterface
+ {abstract} execute(string[optional] $path = null) : string
# load(string $data) : string
# save(string $content, string $path)
# registerPattern(string $pattern, string|callable $replacement = '')
# replace(string $content) : string
# executeReplacement(string|callable $replacement, array $match) : string
# extractStrings(string[optional] $chars = '\'"', string[optional] $placeholderPrefix = '')
# restoreExtractedData(string $content) : string
# canImportFile(string $path) : bool
# openFileForWriting(string $path) : resource
# writeToFile(resource $handler, string $content, ...)
# {static} str_replace_first($search, $replace, ...)
}
note right of Minify::__construct
Init the minify class - optionally, code may be passed along already.
end note
note left of Minify::add
Add a file or straight-up code to be minified.
return: static
end note
note right of Minify::addFile
Add a file to be minified.
return: static
end note
note left of Minify::minify
Minify the data & (optionally) saves it to a file.
return: string
end note
note right of Minify::gzip
Minify & gzip the data & (optionally) saves it to a file.
return: string
end note
note left of Minify::cache
Minify the data & write it to a CacheItemInterface object.
return: CacheItemInterface
end note
note right of Minify::execute
Minify the data.
return: string
end note
note left of Minify::load
Load data.
return: string
end note
note right of Minify::save
Save to file.
end note
note left of Minify::registerPattern
Register a pattern to execute against the source content.
If $replacement is a string, it must be plain text. Placeholders like $1 or \2 don't work.
If you need that functionality, use a callback instead.
end note
note right of Minify::replace
We can't "just" run some regular expressions against JavaScript: it's a
complex language. E.g. having an occurrence of // xyz would be a comment,
unless it's used within a string. Of you could have something that looks
like a 'string', but inside a comment.
The only way to accurately replace these pieces is to traverse the JS one
character at a time and try to find whatever starts first.
return: string
end note
note left of Minify::executeReplacement
If $replacement is a callback, execute it, passing in the match data.
If it's a string, just pass it through.
return: string
end note
note right of Minify::extractStrings
Strings are a pattern we need to match, in order to ignore potential
code-like content inside them, but we just want all of the string
content to remain untouched.
This method will replace all string content with simple STRING#
placeholder text, so we've rid all strings from characters that may be
misinterpreted. Original string content will be saved in $this->extracted
and after doing all other minifying, we can restore the original content
via restoreStrings().
end note
note left of Minify::restoreExtractedData
This method will restore all extracted data (strings, regexes) that were
replaced with placeholder text in extract*(). The original content was
saved in $this->extracted.
return: string
end note
note right of Minify::canImportFile
Check if the path is a regular file and can be read.
return: bool
end note
note left of Minify::openFileForWriting
Attempts to open file specified by $path for writing.
return: resource
end note
note right of Minify::writeToFile
Attempts to write $content to the file specified by $handler. $path is used for printing exceptions.
arguments:
resource $handler
string $content
string $path = ''
end note
note left of Minify::str_replace_first
arguments:
$search
$replace
$subject
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,513 @@
<?php
/**
* Abstract minifier class.
*
* Please report bugs on https://github.com/matthiasmullie/minify/issues
*
* @author Matthias Mullie <minify@mullie.eu>
* @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved
* @license MIT License
*/
namespace VDM\Minify\Abstraction;
use VDM\Minify\Exceptions\IOException;
use VDM\Psr\Cache\CacheItemInterface;
/**
* Abstract minifier class.
*
* Please report bugs on https://github.com/matthiasmullie/minify/issues
*
* @author Matthias Mullie
* @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved
* @license MIT License
*/
abstract class Minify
{
/**
* The data to be minified.
*
* @var string[]
*/
protected $data = [];
/**
* Array of patterns to match.
*
* @var string[]
*/
protected $patterns = [];
/**
* This array will hold content of strings and regular expressions that have
* been extracted from the JS source code, so we can reliably match "code",
* without having to worry about potential "code-like" characters inside.
*
* @internal
*
* @var string[]
*/
public $extracted = [];
/**
* Init the minify class - optionally, code may be passed along already.
*/
public function __construct(/* $data = null, ... */)
{
// it's possible to add the source through the constructor as well ;)
if (func_num_args()) {
call_user_func_array(array($this, 'add'), func_get_args());
}
}
/**
* Add a file or straight-up code to be minified.
*
* @param string|string[] $data
*
* @return static
*/
public function add($data /* $data = null, ... */)
{
// bogus "usage" of parameter $data: scrutinizer warns this variable is
// not used (we're using func_get_args instead to support overloading),
// but it still needs to be defined because it makes no sense to have
// this function without argument :)
$args = array($data) + func_get_args();
// this method can be overloaded
foreach ($args as $data) {
if (is_array($data)) {
call_user_func_array(array($this, 'add'), $data);
continue;
}
// redefine var
$data = (string) $data;
// load data
$value = $this->load($data);
$key = ($data != $value) ? $data : count($this->data);
// replace CR linefeeds etc.
// @see https://github.com/matthiasmullie/minify/pull/139
$value = str_replace(array("\r\n", "\r"), "\n", $value);
// store data
$this->data[$key] = $value;
}
return $this;
}
/**
* Add a file to be minified.
*
* @param string|string[] $data
*
* @return static
*
* @throws IOException
*/
public function addFile($data /* $data = null, ... */)
{
// bogus "usage" of parameter $data: scrutinizer warns this variable is
// not used (we're using func_get_args instead to support overloading),
// but it still needs to be defined because it makes no sense to have
// this function without argument :)
$args = array($data) + func_get_args();
// this method can be overloaded
foreach ($args as $path) {
if (is_array($path)) {
call_user_func_array(array($this, 'addFile'), $path);
continue;
}
// redefine var
$path = (string) $path;
// check if we can read the file
if (!$this->canImportFile($path)) {
throw new IOException('The file "' . $path . '" could not be opened for reading. Check if PHP has enough permissions.');
}
$this->add($path);
}
return $this;
}
/**
* Minify the data & (optionally) saves it to a file.
*
* @param string[optional] $path Path to write the data to
*
* @return string The minified data
*/
public function minify($path = null)
{
$content = $this->execute($path);
// save to path
if ($path !== null) {
$this->save($content, $path);
}
return $content;
}
/**
* Minify & gzip the data & (optionally) saves it to a file.
*
* @param string[optional] $path Path to write the data to
* @param int[optional] $level Compression level, from 0 to 9
*
* @return string The minified & gzipped data
*/
public function gzip($path = null, $level = 9)
{
$content = $this->execute($path);
$content = gzencode($content, $level, FORCE_GZIP);
// save to path
if ($path !== null) {
$this->save($content, $path);
}
return $content;
}
/**
* Minify the data & write it to a CacheItemInterface object.
*
* @param CacheItemInterface $item Cache item to write the data to
*
* @return CacheItemInterface Cache item with the minifier data
*/
public function cache(CacheItemInterface $item)
{
$content = $this->execute();
$item->set($content);
return $item;
}
/**
* Minify the data.
*
* @param string[optional] $path Path to write the data to
*
* @return string The minified data
*/
abstract public function execute($path = null);
/**
* Load data.
*
* @param string $data Either a path to a file or the content itself
*
* @return string
*/
protected function load($data)
{
// check if the data is a file
if ($this->canImportFile($data)) {
$data = file_get_contents($data);
// strip BOM, if any
if (substr($data, 0, 3) == "\xef\xbb\xbf") {
$data = substr($data, 3);
}
}
return $data;
}
/**
* Save to file.
*
* @param string $content The minified data
* @param string $path The path to save the minified data to
*
* @throws IOException
*/
protected function save($content, $path)
{
$handler = $this->openFileForWriting($path);
$this->writeToFile($handler, $content);
@fclose($handler);
}
/**
* Register a pattern to execute against the source content.
*
* If $replacement is a string, it must be plain text. Placeholders like $1 or \2 don't work.
* If you need that functionality, use a callback instead.
*
* @param string $pattern PCRE pattern
* @param string|callable $replacement Replacement value for matched pattern
*/
protected function registerPattern($pattern, $replacement = '')
{
// study the pattern, we'll execute it more than once
$pattern .= 'S';
$this->patterns[] = array($pattern, $replacement);
}
/**
* We can't "just" run some regular expressions against JavaScript: it's a
* complex language. E.g. having an occurrence of // xyz would be a comment,
* unless it's used within a string. Of you could have something that looks
* like a 'string', but inside a comment.
* The only way to accurately replace these pieces is to traverse the JS one
* character at a time and try to find whatever starts first.
*
* @param string $content The content to replace patterns in
*
* @return string The (manipulated) content
*/
protected function replace($content)
{
$contentLength = strlen($content);
$output = '';
$processedOffset = 0;
$positions = array_fill(0, count($this->patterns), -1);
$matches = [];
while ($processedOffset < $contentLength) {
// find first match for all patterns
foreach ($this->patterns as $i => $pattern) {
list($pattern, $replacement) = $pattern;
// we can safely ignore patterns for positions we've unset earlier,
// because we know these won't show up anymore
if (array_key_exists($i, $positions) == false) {
continue;
}
// no need to re-run matches that are still in the part of the
// content that hasn't been processed
if ($positions[$i] >= $processedOffset) {
continue;
}
$match = null;
if (preg_match($pattern, $content, $match, PREG_OFFSET_CAPTURE, $processedOffset)) {
$matches[$i] = $match;
// we'll store the match position as well; that way, we
// don't have to redo all preg_matches after changing only
// the first (we'll still know where those others are)
$positions[$i] = $match[0][1];
} else {
// if the pattern couldn't be matched, there's no point in
// executing it again in later runs on this same content;
// ignore this one until we reach end of content
unset($matches[$i], $positions[$i]);
}
}
// no more matches to find: everything's been processed, break out
if (!$matches) {
// output the remaining content
$output .= substr($content, $processedOffset);
break;
}
// see which of the patterns actually found the first thing (we'll
// only want to execute that one, since we're unsure if what the
// other found was not inside what the first found)
$matchOffset = min($positions);
$firstPattern = array_search($matchOffset, $positions);
$match = $matches[$firstPattern];
// execute the pattern that matches earliest in the content string
list(, $replacement) = $this->patterns[$firstPattern];
// add the part of the input between $processedOffset and the first match;
// that content wasn't matched by anything
$output .= substr($content, $processedOffset, $matchOffset - $processedOffset);
// add the replacement for the match
$output .= $this->executeReplacement($replacement, $match);
// advance $processedOffset past the match
$processedOffset = $matchOffset + strlen($match[0][0]);
}
return $output;
}
/**
* If $replacement is a callback, execute it, passing in the match data.
* If it's a string, just pass it through.
*
* @param string|callable $replacement Replacement value
* @param array $match Match data, in PREG_OFFSET_CAPTURE form
*
* @return string
*/
protected function executeReplacement($replacement, $match)
{
if (!is_callable($replacement)) {
return $replacement;
}
// convert $match from the PREG_OFFSET_CAPTURE form to the form the callback expects
foreach ($match as &$matchItem) {
$matchItem = $matchItem[0];
}
return $replacement($match);
}
/**
* Strings are a pattern we need to match, in order to ignore potential
* code-like content inside them, but we just want all of the string
* content to remain untouched.
*
* This method will replace all string content with simple STRING#
* placeholder text, so we've rid all strings from characters that may be
* misinterpreted. Original string content will be saved in $this->extracted
* and after doing all other minifying, we can restore the original content
* via restoreStrings().
*
* @param string[optional] $chars
* @param string[optional] $placeholderPrefix
*/
protected function extractStrings($chars = '\'"', $placeholderPrefix = '')
{
// PHP only supports $this inside anonymous functions since 5.4
$minifier = $this;
$callback = function ($match) use ($minifier, $placeholderPrefix) {
// check the second index here, because the first always contains a quote
if ($match[2] === '') {
/*
* Empty strings need no placeholder; they can't be confused for
* anything else anyway.
* But we still needed to match them, for the extraction routine
* to skip over this particular string.
*/
return $match[0];
}
$count = count($minifier->extracted);
$placeholder = $match[1] . $placeholderPrefix . $count . $match[1];
$minifier->extracted[$placeholder] = $match[1] . $match[2] . $match[1];
return $placeholder;
};
/*
* The \\ messiness explained:
* * Don't count ' or " as end-of-string if it's escaped (has backslash
* in front of it)
* * Unless... that backslash itself is escaped (another leading slash),
* in which case it's no longer escaping the ' or "
* * So there can be either no backslash, or an even number
* * multiply all of that times 4, to account for the escaping that has
* to be done to pass the backslash into the PHP string without it being
* considered as escape-char (times 2) and to get it in the regex,
* escaped (times 2)
*/
$this->registerPattern('/([' . $chars . '])(.*?(?<!\\\\)(\\\\\\\\)*+)\\1/s', $callback);
}
/**
* This method will restore all extracted data (strings, regexes) that were
* replaced with placeholder text in extract*(). The original content was
* saved in $this->extracted.
*
* @param string $content
*
* @return string
*/
protected function restoreExtractedData($content)
{
if (!$this->extracted) {
// nothing was extracted, nothing to restore
return $content;
}
$content = strtr($content, $this->extracted);
$this->extracted = [];
return $content;
}
/**
* Check if the path is a regular file and can be read.
*
* @param string $path
*
* @return bool
*/
protected function canImportFile($path)
{
$parsed = parse_url($path);
if (
// file is elsewhere
isset($parsed['host']) ||
// file responds to queries (may change, or need to bypass cache)
isset($parsed['query'])
) {
return false;
}
return strlen($path) < PHP_MAXPATHLEN && @is_file($path) && is_readable($path);
}
/**
* Attempts to open file specified by $path for writing.
*
* @param string $path The path to the file
*
* @return resource Specifier for the target file
*
* @throws IOException
*/
protected function openFileForWriting($path)
{
if ($path === '' || ($handler = @fopen($path, 'w')) === false) {
throw new IOException('The file "' . $path . '" could not be opened for writing. Check if PHP has enough permissions.');
}
return $handler;
}
/**
* Attempts to write $content to the file specified by $handler. $path is used for printing exceptions.
*
* @param resource $handler The resource to write to
* @param string $content The content to write
* @param string $path The path to the file (for exception printing only)
*
* @throws IOException
*/
protected function writeToFile($handler, $content, $path = '')
{
if (
!is_resource($handler) ||
($result = @fwrite($handler, $content)) === false ||
($result < strlen($content))
) {
throw new IOException('The file "' . $path . '" could not be written to. Check your disk space and file permissions.');
}
}
protected static function str_replace_first($search, $replace, $subject)
{
$pos = strpos((string) $subject, (string) $search);
if ($pos !== false) {
return substr_replace((string) $subject, (string) $replace, $pos, strlen((string) $search));
}
return $subject;
}
}

View File

@ -0,0 +1,482 @@
/**
* The data to be minified.
*
* @var string[]
*/
protected $data = [];
/**
* Array of patterns to match.
*
* @var string[]
*/
protected $patterns = [];
/**
* This array will hold content of strings and regular expressions that have
* been extracted from the JS source code, so we can reliably match "code",
* without having to worry about potential "code-like" characters inside.
*
* @internal
*
* @var string[]
*/
public $extracted = [];
/**
* Init the minify class - optionally, code may be passed along already.
*/
public function __construct(/* $data = null, ... */)
{
// it's possible to add the source through the constructor as well ;)
if (func_num_args()) {
call_user_func_array(array($this, 'add'), func_get_args());
}
}
/**
* Add a file or straight-up code to be minified.
*
* @param string|string[] $data
*
* @return static
*/
public function add($data /* $data = null, ... */)
{
// bogus "usage" of parameter $data: scrutinizer warns this variable is
// not used (we're using func_get_args instead to support overloading),
// but it still needs to be defined because it makes no sense to have
// this function without argument :)
$args = array($data) + func_get_args();
// this method can be overloaded
foreach ($args as $data) {
if (is_array($data)) {
call_user_func_array(array($this, 'add'), $data);
continue;
}
// redefine var
$data = (string) $data;
// load data
$value = $this->load($data);
$key = ($data != $value) ? $data : count($this->data);
// replace CR linefeeds etc.
// @see https://github.com/matthiasmullie/minify/pull/139
$value = str_replace(array("\r\n", "\r"), "\n", $value);
// store data
$this->data[$key] = $value;
}
return $this;
}
/**
* Add a file to be minified.
*
* @param string|string[] $data
*
* @return static
*
* @throws IOException
*/
public function addFile($data /* $data = null, ... */)
{
// bogus "usage" of parameter $data: scrutinizer warns this variable is
// not used (we're using func_get_args instead to support overloading),
// but it still needs to be defined because it makes no sense to have
// this function without argument :)
$args = array($data) + func_get_args();
// this method can be overloaded
foreach ($args as $path) {
if (is_array($path)) {
call_user_func_array(array($this, 'addFile'), $path);
continue;
}
// redefine var
$path = (string) $path;
// check if we can read the file
if (!$this->canImportFile($path)) {
throw new IOException('The file "' . $path . '" could not be opened for reading. Check if PHP has enough permissions.');
}
$this->add($path);
}
return $this;
}
/**
* Minify the data & (optionally) saves it to a file.
*
* @param string[optional] $path Path to write the data to
*
* @return string The minified data
*/
public function minify($path = null)
{
$content = $this->execute($path);
// save to path
if ($path !== null) {
$this->save($content, $path);
}
return $content;
}
/**
* Minify & gzip the data & (optionally) saves it to a file.
*
* @param string[optional] $path Path to write the data to
* @param int[optional] $level Compression level, from 0 to 9
*
* @return string The minified & gzipped data
*/
public function gzip($path = null, $level = 9)
{
$content = $this->execute($path);
$content = gzencode($content, $level, FORCE_GZIP);
// save to path
if ($path !== null) {
$this->save($content, $path);
}
return $content;
}
/**
* Minify the data & write it to a CacheItemInterface object.
*
* @param CacheItemInterface $item Cache item to write the data to
*
* @return CacheItemInterface Cache item with the minifier data
*/
public function cache(CacheItemInterface $item)
{
$content = $this->execute();
$item->set($content);
return $item;
}
/**
* Minify the data.
*
* @param string[optional] $path Path to write the data to
*
* @return string The minified data
*/
abstract public function execute($path = null);
/**
* Load data.
*
* @param string $data Either a path to a file or the content itself
*
* @return string
*/
protected function load($data)
{
// check if the data is a file
if ($this->canImportFile($data)) {
$data = file_get_contents($data);
// strip BOM, if any
if (substr($data, 0, 3) == "\xef\xbb\xbf") {
$data = substr($data, 3);
}
}
return $data;
}
/**
* Save to file.
*
* @param string $content The minified data
* @param string $path The path to save the minified data to
*
* @throws IOException
*/
protected function save($content, $path)
{
$handler = $this->openFileForWriting($path);
$this->writeToFile($handler, $content);
@fclose($handler);
}
/**
* Register a pattern to execute against the source content.
*
* If $replacement is a string, it must be plain text. Placeholders like $1 or \2 don't work.
* If you need that functionality, use a callback instead.
*
* @param string $pattern PCRE pattern
* @param string|callable $replacement Replacement value for matched pattern
*/
protected function registerPattern($pattern, $replacement = '')
{
// study the pattern, we'll execute it more than once
$pattern .= 'S';
$this->patterns[] = array($pattern, $replacement);
}
/**
* We can't "just" run some regular expressions against JavaScript: it's a
* complex language. E.g. having an occurrence of // xyz would be a comment,
* unless it's used within a string. Of you could have something that looks
* like a 'string', but inside a comment.
* The only way to accurately replace these pieces is to traverse the JS one
* character at a time and try to find whatever starts first.
*
* @param string $content The content to replace patterns in
*
* @return string The (manipulated) content
*/
protected function replace($content)
{
$contentLength = strlen($content);
$output = '';
$processedOffset = 0;
$positions = array_fill(0, count($this->patterns), -1);
$matches = [];
while ($processedOffset < $contentLength) {
// find first match for all patterns
foreach ($this->patterns as $i => $pattern) {
list($pattern, $replacement) = $pattern;
// we can safely ignore patterns for positions we've unset earlier,
// because we know these won't show up anymore
if (array_key_exists($i, $positions) == false) {
continue;
}
// no need to re-run matches that are still in the part of the
// content that hasn't been processed
if ($positions[$i] >= $processedOffset) {
continue;
}
$match = null;
if (preg_match($pattern, $content, $match, PREG_OFFSET_CAPTURE, $processedOffset)) {
$matches[$i] = $match;
// we'll store the match position as well; that way, we
// don't have to redo all preg_matches after changing only
// the first (we'll still know where those others are)
$positions[$i] = $match[0][1];
} else {
// if the pattern couldn't be matched, there's no point in
// executing it again in later runs on this same content;
// ignore this one until we reach end of content
unset($matches[$i], $positions[$i]);
}
}
// no more matches to find: everything's been processed, break out
if (!$matches) {
// output the remaining content
$output .= substr($content, $processedOffset);
break;
}
// see which of the patterns actually found the first thing (we'll
// only want to execute that one, since we're unsure if what the
// other found was not inside what the first found)
$matchOffset = min($positions);
$firstPattern = array_search($matchOffset, $positions);
$match = $matches[$firstPattern];
// execute the pattern that matches earliest in the content string
list(, $replacement) = $this->patterns[$firstPattern];
// add the part of the input between $processedOffset and the first match;
// that content wasn't matched by anything
$output .= substr($content, $processedOffset, $matchOffset - $processedOffset);
// add the replacement for the match
$output .= $this->executeReplacement($replacement, $match);
// advance $processedOffset past the match
$processedOffset = $matchOffset + strlen($match[0][0]);
}
return $output;
}
/**
* If $replacement is a callback, execute it, passing in the match data.
* If it's a string, just pass it through.
*
* @param string|callable $replacement Replacement value
* @param array $match Match data, in PREG_OFFSET_CAPTURE form
*
* @return string
*/
protected function executeReplacement($replacement, $match)
{
if (!is_callable($replacement)) {
return $replacement;
}
// convert $match from the PREG_OFFSET_CAPTURE form to the form the callback expects
foreach ($match as &$matchItem) {
$matchItem = $matchItem[0];
}
return $replacement($match);
}
/**
* Strings are a pattern we need to match, in order to ignore potential
* code-like content inside them, but we just want all of the string
* content to remain untouched.
*
* This method will replace all string content with simple STRING#
* placeholder text, so we've rid all strings from characters that may be
* misinterpreted. Original string content will be saved in $this->extracted
* and after doing all other minifying, we can restore the original content
* via restoreStrings().
*
* @param string[optional] $chars
* @param string[optional] $placeholderPrefix
*/
protected function extractStrings($chars = '\'"', $placeholderPrefix = '')
{
// PHP only supports $this inside anonymous functions since 5.4
$minifier = $this;
$callback = function ($match) use ($minifier, $placeholderPrefix) {
// check the second index here, because the first always contains a quote
if ($match[2] === '') {
/*
* Empty strings need no placeholder; they can't be confused for
* anything else anyway.
* But we still needed to match them, for the extraction routine
* to skip over this particular string.
*/
return $match[0];
}
$count = count($minifier->extracted);
$placeholder = $match[1] . $placeholderPrefix . $count . $match[1];
$minifier->extracted[$placeholder] = $match[1] . $match[2] . $match[1];
return $placeholder;
};
/*
* The \\ messiness explained:
* * Don't count ' or " as end-of-string if it's escaped (has backslash
* in front of it)
* * Unless... that backslash itself is escaped (another leading slash),
* in which case it's no longer escaping the ' or "
* * So there can be either no backslash, or an even number
* * multiply all of that times 4, to account for the escaping that has
* to be done to pass the backslash into the PHP string without it being
* considered as escape-char (times 2) and to get it in the regex,
* escaped (times 2)
*/
$this->registerPattern('/([' . $chars . '])(.*?(?<!\\\\)(\\\\\\\\)*+)\\1/s', $callback);
}
/**
* This method will restore all extracted data (strings, regexes) that were
* replaced with placeholder text in extract*(). The original content was
* saved in $this->extracted.
*
* @param string $content
*
* @return string
*/
protected function restoreExtractedData($content)
{
if (!$this->extracted) {
// nothing was extracted, nothing to restore
return $content;
}
$content = strtr($content, $this->extracted);
$this->extracted = [];
return $content;
}
/**
* Check if the path is a regular file and can be read.
*
* @param string $path
*
* @return bool
*/
protected function canImportFile($path)
{
$parsed = parse_url($path);
if (
// file is elsewhere
isset($parsed['host']) ||
// file responds to queries (may change, or need to bypass cache)
isset($parsed['query'])
) {
return false;
}
return strlen($path) < PHP_MAXPATHLEN && @is_file($path) && is_readable($path);
}
/**
* Attempts to open file specified by $path for writing.
*
* @param string $path The path to the file
*
* @return resource Specifier for the target file
*
* @throws IOException
*/
protected function openFileForWriting($path)
{
if ($path === '' || ($handler = @fopen($path, 'w')) === false) {
throw new IOException('The file "' . $path . '" could not be opened for writing. Check if PHP has enough permissions.');
}
return $handler;
}
/**
* Attempts to write $content to the file specified by $handler. $path is used for printing exceptions.
*
* @param resource $handler The resource to write to
* @param string $content The content to write
* @param string $path The path to the file (for exception printing only)
*
* @throws IOException
*/
protected function writeToFile($handler, $content, $path = '')
{
if (
!is_resource($handler) ||
($result = @fwrite($handler, $content)) === false ||
($result < strlen($content))
) {
throw new IOException('The file "' . $path . '" could not be written to. Check your disk space and file permissions.');
}
}
protected static function str_replace_first($search, $replace, $subject)
{
$pos = strpos((string) $subject, (string) $search);
if ($pos !== false) {
return substr_replace((string) $subject, (string) $replace, $pos, strlen((string) $search));
}
return $subject;
}

View File

@ -0,0 +1,27 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "0",
"guid": "d2b8599a-d5ce-49b1-b992-764bb7d55137",
"implements": null,
"load_selection": null,
"name": "Minify",
"power_version": "1.3.70",
"system_name": "Minify.Abstraction.Minify",
"type": "abstract class",
"use_selection": {
"use_selection0": {
"use": "44b4a9cf-62e6-48af-ab30-5b3d2715728e",
"as": "default"
},
"use_selection1": {
"use": "171fcb39-ae27-4c2b-b091-2f70b824288b",
"as": "default"
}
},
"namespace": "VDM\\Minify\\Abstraction.Minify",
"description": "\/**\r\n * Abstract minifier class.\r\n *\r\n * Please report bugs on https:\/\/github.com\/matthiasmullie\/minify\/issues\r\n *\r\n * @author Matthias Mullie \r\n * @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved\r\n * @license MIT License\r\n *\/",
"licensing_template": "\/**\r\n * Abstract minifier class.\r\n *\r\n * Please report bugs on https:\/\/github.com\/matthiasmullie\/minify\/issues\r\n *\r\n * @author Matthias Mullie <minify@mullie.eu>\r\n * @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved\r\n * @license MIT License\r\n *\/\r\n",
"head": "",
"composer": ""
}

View File

@ -0,0 +1,108 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# class JavaScript (Details)
> namespace: **VDM\Minify**
```uml
@startuml
class JavaScript #Gold {
# $keywordsReserved
# $keywordsBefore
# $keywordsAfter
# $operatorsBefore
+ execute(string[optional] $path = null) : string
# stripComments()
# extractRegex()
# stripWhitespace(string $content) : string
# getOperatorsForRegex(array $operators, string $delimiter = '/') : string[]
# getKeywordsForRegex(array $keywords, string $delimiter = '/') : string[]
# propertyNotation(string $content) : string
# shortenBools(string $content) : string
}
note right of JavaScript::execute
Minify the data.
Perform JS optimizations.
return: string
end note
note left of JavaScript::stripComments
Strip comments from source code.
end note
note right of JavaScript::extractRegex
JS can have /-delimited regular expressions, like: /ab+c/.match(string).
The content inside the regex can contain characters that may be confused
for JS code: e.g. it could contain whitespace it needs to match & we
don't want to strip whitespace in there.
The regex can be pretty simple: we don't have to care about comments,
(which also use slashes) because stripComments() will have stripped those
already.
This method will replace all string content with simple REGEX#
placeholder text, so we've rid all regular expressions from characters
that may be misinterpreted. Original regex content will be saved in
$this->extracted and after doing all other minifying, we can restore the
original content via restoreRegex()
end note
note left of JavaScript::stripWhitespace
Strip whitespace.
We won't strip *all* whitespace, but as much as possible. The thing that
we'll preserve are newlines we're unsure about.
JavaScript doesn't require statements to be terminated with a semicolon.
It will automatically fix missing semicolons with ASI (automatic semi-
colon insertion) at the end of line causing errors (without semicolon.)
Because it's sometimes hard to tell if a newline is part of a statement
that should be terminated or not, we'll just leave some of them alone.
return: string
end note
note right of JavaScript::getOperatorsForRegex
We'll strip whitespace around certain operators with regular expressions.
This will prepare the given array by escaping all characters.
return: string[]
end note
note left of JavaScript::getKeywordsForRegex
We'll strip whitespace around certain keywords with regular expressions.
This will prepare the given array by escaping all characters.
return: string[]
end note
note right of JavaScript::propertyNotation
Replaces all occurrences of array['key'] by array.key.
return: string
end note
note left of JavaScript::shortenBools
Replaces true & false by !0 and !1.
return: string
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,18 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "d2b8599a-d5ce-49b1-b992-764bb7d55137",
"guid": "ef6438c4-76db-4aa1-bb15-bc97583bcd2e",
"implements": null,
"load_selection": null,
"name": "JavaScript",
"power_version": "1.3.70",
"system_name": "Minify.JavaScript",
"type": "class",
"use_selection": null,
"namespace": "VDM\\Minify\\JavaScript",
"description": "\/**\r\n * JavaScript Minifier Class.\r\n *\r\n * Please report bugs on https:\/\/github.com\/matthiasmullie\/minify\/issues\r\n *\r\n * @author Matthias Mullie \r\n * @author Tijs Verkoyen \r\n * @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved\r\n * @license MIT License\r\n *\/",
"licensing_template": "\/**\r\n * JavaScript minifier.\r\n *\r\n * Please report bugs on https:\/\/github.com\/matthiasmullie\/minify\/issues\r\n *\r\n * @author Matthias Mullie <minify@mullie.eu>\r\n * @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved\r\n * @license MIT License\r\n *\/",
"head": "",
"composer": ""
}

92
super-powers.json Normal file
View File

@ -0,0 +1,92 @@
{
"47448ada-54df-45f3-b05d-1c66c584b1bd": {
"name": "BasicException",
"type": "abstract class",
"namespace": "VDM\\Minify\\Abstraction",
"code": "src\/47448ada-54df-45f3-b05d-1c66c584b1bd\/code.php",
"power": "src\/47448ada-54df-45f3-b05d-1c66c584b1bd\/code.power",
"settings": "src\/47448ada-54df-45f3-b05d-1c66c584b1bd\/settings.json",
"path": "src\/47448ada-54df-45f3-b05d-1c66c584b1bd",
"guid": "47448ada-54df-45f3-b05d-1c66c584b1bd"
},
"44b4a9cf-62e6-48af-ab30-5b3d2715728e": {
"name": "IOException",
"type": "class",
"namespace": "VDM\\Minify\\Exceptions",
"code": "src\/44b4a9cf-62e6-48af-ab30-5b3d2715728e\/code.php",
"power": "src\/44b4a9cf-62e6-48af-ab30-5b3d2715728e\/code.power",
"settings": "src\/44b4a9cf-62e6-48af-ab30-5b3d2715728e\/settings.json",
"path": "src\/44b4a9cf-62e6-48af-ab30-5b3d2715728e",
"guid": "44b4a9cf-62e6-48af-ab30-5b3d2715728e"
},
"d2b8599a-d5ce-49b1-b992-764bb7d55137": {
"name": "Minify",
"type": "abstract class",
"namespace": "VDM\\Minify\\Abstraction",
"code": "src\/d2b8599a-d5ce-49b1-b992-764bb7d55137\/code.php",
"power": "src\/d2b8599a-d5ce-49b1-b992-764bb7d55137\/code.power",
"settings": "src\/d2b8599a-d5ce-49b1-b992-764bb7d55137\/settings.json",
"path": "src\/d2b8599a-d5ce-49b1-b992-764bb7d55137",
"guid": "d2b8599a-d5ce-49b1-b992-764bb7d55137"
},
"b34dbbeb-89bd-4f01-8bbd-f7ba0fb6280b": {
"name": "FileImportException",
"type": "class",
"namespace": "VDM\\Minify\\Exceptions",
"code": "src\/b34dbbeb-89bd-4f01-8bbd-f7ba0fb6280b\/code.php",
"power": "src\/b34dbbeb-89bd-4f01-8bbd-f7ba0fb6280b\/code.power",
"settings": "src\/b34dbbeb-89bd-4f01-8bbd-f7ba0fb6280b\/settings.json",
"path": "src\/b34dbbeb-89bd-4f01-8bbd-f7ba0fb6280b",
"guid": "b34dbbeb-89bd-4f01-8bbd-f7ba0fb6280b"
},
"cc482882-5eef-476c-b835-7b0c5a17c0db": {
"name": "ConverterInterface",
"type": "interface",
"namespace": "VDM\\Minify\\Path\\Interfaces",
"code": "src\/cc482882-5eef-476c-b835-7b0c5a17c0db\/code.php",
"power": "src\/cc482882-5eef-476c-b835-7b0c5a17c0db\/code.power",
"settings": "src\/cc482882-5eef-476c-b835-7b0c5a17c0db\/settings.json",
"path": "src\/cc482882-5eef-476c-b835-7b0c5a17c0db",
"guid": "cc482882-5eef-476c-b835-7b0c5a17c0db"
},
"39f8957f-cc73-4da5-8b60-6cf25d4ab058": {
"name": "Converter",
"type": "class",
"namespace": "VDM\\Minify\\Path",
"code": "src\/39f8957f-cc73-4da5-8b60-6cf25d4ab058\/code.php",
"power": "src\/39f8957f-cc73-4da5-8b60-6cf25d4ab058\/code.power",
"settings": "src\/39f8957f-cc73-4da5-8b60-6cf25d4ab058\/settings.json",
"path": "src\/39f8957f-cc73-4da5-8b60-6cf25d4ab058",
"guid": "39f8957f-cc73-4da5-8b60-6cf25d4ab058"
},
"70530246-2903-4c02-af9a-61182e4d97b8": {
"name": "Css",
"type": "class",
"namespace": "VDM\\Minify",
"code": "src\/70530246-2903-4c02-af9a-61182e4d97b8\/code.php",
"power": "src\/70530246-2903-4c02-af9a-61182e4d97b8\/code.power",
"settings": "src\/70530246-2903-4c02-af9a-61182e4d97b8\/settings.json",
"path": "src\/70530246-2903-4c02-af9a-61182e4d97b8",
"guid": "70530246-2903-4c02-af9a-61182e4d97b8"
},
"ef6438c4-76db-4aa1-bb15-bc97583bcd2e": {
"name": "JavaScript",
"type": "class",
"namespace": "VDM\\Minify",
"code": "src\/ef6438c4-76db-4aa1-bb15-bc97583bcd2e\/code.php",
"power": "src\/ef6438c4-76db-4aa1-bb15-bc97583bcd2e\/code.power",
"settings": "src\/ef6438c4-76db-4aa1-bb15-bc97583bcd2e\/settings.json",
"path": "src\/ef6438c4-76db-4aa1-bb15-bc97583bcd2e",
"guid": "ef6438c4-76db-4aa1-bb15-bc97583bcd2e"
},
"b591855d-d106-4fe5-90ad-8e706f6267cf": {
"name": "Minify",
"type": "abstract class",
"namespace": "VDM\\Joomla\\Componentbuilder\\Compiler\\Utilities",
"code": "src\/b591855d-d106-4fe5-90ad-8e706f6267cf\/code.php",
"power": "src\/b591855d-d106-4fe5-90ad-8e706f6267cf\/code.power",
"settings": "src\/b591855d-d106-4fe5-90ad-8e706f6267cf\/settings.json",
"path": "src\/b591855d-d106-4fe5-90ad-8e706f6267cf",
"guid": "b591855d-d106-4fe5-90ad-8e706f6267cf"
}
}