Skip to content

Commit 4b84d11

Browse files
committed
Update minify dependencies
1 parent 505af19 commit 4b84d11

File tree

16 files changed

+447
-328
lines changed

16 files changed

+447
-328
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"coenjacobs/mozart": "^0.7.1",
2727
"matthiasmullie/minify": "^1.3",
2828
"deliciousbrains/wp-background-processing": "^1.3",
29-
"voku/html-min": "^4.4.10"
29+
"voku/html-min": "^4.5"
3030
},
3131
"scripts": {
3232
"lint": "phpcs powered-cache.php uninstall.php ./includes -s",

composer.lock

Lines changed: 276 additions & 257 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/classes/Dependencies/MatthiasMullie/Minify/CSS.php

Lines changed: 126 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ protected function moveImportsToTop($content)
106106
/**
107107
* Combine CSS from import statements.
108108
*
109-
* Import statements will be loaded and their content merged into the original
110-
* file, to save HTTP requests.
109+
* \@import's will be loaded and their content merged into the original file,
110+
* to save HTTP requests.
111111
*
112112
* @param string $source The file to combine imports for
113113
* @param string $content The CSS content to combine imports for
@@ -316,7 +316,9 @@ public function execute($path = null, $parents = array())
316316
$css = $this->replace($css);
317317

318318
$css = $this->stripWhitespace($css);
319-
$css = $this->shortenColors($css);
319+
$css = $this->convertLegacyColors($css);
320+
$css = $this->cleanupModernColors($css);
321+
$css = $this->shortenHEXColors($css);
320322
$css = $this->shortenZeroes($css);
321323
$css = $this->shortenFontWeights($css);
322324
$css = $this->stripEmptyTags($css);
@@ -480,64 +482,153 @@ protected function move(ConverterInterface $converter, $content)
480482
}
481483

482484
/**
483-
* Shorthand hex color codes.
484-
* #FF0000 -> #F00.
485+
* Shorthand HEX color codes.
486+
* #FF0000FF -> #f00 -> red
487+
* #FF00FF00 -> transparent.
485488
*
486-
* @param string $content The CSS content to shorten the hex color codes for
489+
* @param string $content The CSS content to shorten the HEX color codes for
487490
*
488491
* @return string
489492
*/
490-
protected function shortenColors($content)
493+
protected function shortenHexColors($content)
491494
{
492-
$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);
495+
// shorten repeating patterns within HEX ..
496+
$content = preg_replace('/(?<=[: ])#([0-9a-f])\\1([0-9a-f])\\2([0-9a-f])\\3(?:([0-9a-f])\\4)?(?=[; }])/i', '#$1$2$3$4', $content);
493497

494-
// remove alpha channel if it's pointless...
495-
$content = preg_replace('/(?<=[: ])#([0-9a-z]{6})ff?(?=[; }])/i', '#$1', $content);
496-
$content = preg_replace('/(?<=[: ])#([0-9a-z]{3})f?(?=[; }])/i', '#$1', $content);
498+
// remove alpha channel if it's pointless ..
499+
$content = preg_replace('/(?<=[: ])#([0-9a-f]{6})ff(?=[; }])/i', '#$1', $content);
500+
$content = preg_replace('/(?<=[: ])#([0-9a-f]{3})f(?=[; }])/i', '#$1', $content);
501+
502+
// replace `transparent` with shortcut ..
503+
$content = preg_replace('/(?<=[: ])#[0-9a-f]{6}00(?=[; }])/i', '#fff0', $content);
497504

498505
$colors = array(
506+
// make these more readable
507+
'#00f' => 'blue',
508+
'#dc143c' => 'crimson',
509+
'#0ff' => 'cyan',
510+
'#8b0000' => 'darkred',
511+
'#696969' => 'dimgray',
512+
'#ff69b4' => 'hotpink',
513+
'#0f0' => 'lime',
514+
'#fdf5e6' => 'oldlace',
515+
'#87ceeb' => 'skyblue',
516+
'#d8bfd8' => 'thistle',
499517
// we can shorten some even more by replacing them with their color name
500-
'#F0FFFF' => 'azure',
501-
'#F5F5DC' => 'beige',
502-
'#A52A2A' => 'brown',
503-
'#FF7F50' => 'coral',
504-
'#FFD700' => 'gold',
518+
'#f0ffff' => 'azure',
519+
'#f5f5dc' => 'beige',
520+
'#ffe4c4' => 'bisque',
521+
'#a52a2a' => 'brown',
522+
'#ff7f50' => 'coral',
523+
'#ffd700' => 'gold',
505524
'#808080' => 'gray',
506525
'#008000' => 'green',
507-
'#4B0082' => 'indigo',
508-
'#FFFFF0' => 'ivory',
509-
'#F0E68C' => 'khaki',
510-
'#FAF0E6' => 'linen',
526+
'#4b0082' => 'indigo',
527+
'#fffff0' => 'ivory',
528+
'#f0e68c' => 'khaki',
529+
'#faf0e6' => 'linen',
511530
'#800000' => 'maroon',
512531
'#000080' => 'navy',
513532
'#808000' => 'olive',
514-
'#CD853F' => 'peru',
515-
'#FFC0CB' => 'pink',
516-
'#DDA0DD' => 'plum',
533+
'#ffa500' => 'orange',
534+
'#da70d6' => 'orchid',
535+
'#cd853f' => 'peru',
536+
'#ffc0cb' => 'pink',
537+
'#dda0dd' => 'plum',
517538
'#800080' => 'purple',
518-
'#F00' => 'red',
519-
'#FA8072' => 'salmon',
520-
'#A0522D' => 'sienna',
521-
'#C0C0C0' => 'silver',
522-
'#FFFAFA' => 'snow',
523-
'#D2B48C' => 'tan',
524-
'#FF6347' => 'tomato',
525-
'#EE82EE' => 'violet',
526-
'#F5DEB3' => 'wheat',
539+
'#f00' => 'red',
540+
'#fa8072' => 'salmon',
541+
'#a0522d' => 'sienna',
542+
'#c0c0c0' => 'silver',
543+
'#fffafa' => 'snow',
544+
'#d2b48c' => 'tan',
545+
'#008080' => 'teal',
546+
'#ff6347' => 'tomato',
547+
'#ee82ee' => 'violet',
548+
'#f5deb3' => 'wheat',
527549
// or the other way around
528-
'WHITE' => '#fff',
529-
'BLACK' => '#000',
550+
'black' => '#000',
551+
'fuchsia' => '#f0f',
552+
'magenta' => '#f0f',
553+
'white' => '#fff',
554+
'yellow' => '#ff0',
555+
// and also `transparent`
556+
'transparent' => '#fff0',
530557
);
531558

532559
return preg_replace_callback(
533560
'/(?<=[: ])(' . implode('|', array_keys($colors)) . ')(?=[; }])/i',
534561
function ($match) use ($colors) {
535-
return $colors[strtoupper($match[0])];
562+
return $colors[strtolower($match[0])];
563+
},
564+
$content
565+
);
566+
}
567+
568+
/**
569+
* Convert RGB|HSL color codes.
570+
* rgb(255,0,0,.5) -> rgb(255 0 0 / .5).
571+
* rgb(255,0,0) -> #f00.
572+
*
573+
* @param string $content The CSS content to shorten the RGB color codes for
574+
*
575+
* @return string
576+
*/
577+
protected function convertLegacyColors($content)
578+
{
579+
/*
580+
https://drafts.csswg.org/css-color/#color-syntax-legacy
581+
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/rgb
582+
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/hsl
583+
*/
584+
585+
// convert legacy color syntax
586+
$content = preg_replace('/(rgb)a?\(\s*([0-9]{1,3}%?)\s*,\s*([0-9]{1,3}%?)\s*,\s*([0-9]{1,3}%?)\s*,\s*([0,1]?(?:\.[0-9]*)?)\s*\)/i', '$1($2 $3 $4 / $5)', $content);
587+
$content = preg_replace('/(rgb)a?\(\s*([0-9]{1,3}%?)\s*,\s*([0-9]{1,3}%?)\s*,\s*([0-9]{1,3}%?)\s*\)/i', '$1($2 $3 $4)', $content);
588+
$content = preg_replace('/(hsl)a?\(\s*([0-9]+(?:deg|grad|rad|turn)?)\s*,\s*([0-9]{1,3}%)\s*,\s*([0-9]{1,3}%)\s*,\s*([0,1]?(?:\.[0-9]*)?)\s*\)/i', '$1($2 $3 $4 / $5)', $content);
589+
$content = preg_replace('/(hsl)a?\(\s*([0-9]+(?:deg|grad|rad|turn)?)\s*,\s*([0-9]{1,3}%)\s*,\s*([0-9]{1,3}%)\s*\)/i', '$1($2 $3 $4)', $content);
590+
591+
// convert `rgb` to `hex`
592+
$dec = '([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])';
593+
return preg_replace_callback(
594+
"/rgb\($dec $dec $dec\)/i",
595+
function ($match) {
596+
return sprintf('#%02x%02x%02x', $match[1], $match[2], $match[3]);
536597
},
537598
$content
538599
);
539600
}
540601

602+
/**
603+
* Cleanup RGB|HSL|HWB|LCH|LAB
604+
* rgb(255 0 0 / 1) -> rgb(255 0 0).
605+
* rgb(255 0 0 / 0) -> transparent.
606+
*
607+
* @param string $content The CSS content to cleanup HSL|HWB|LCH|LAB
608+
*
609+
* @return string
610+
*/
611+
protected function cleanupModernColors($content)
612+
{
613+
/*
614+
https://drafts.csswg.org/css-color/#color-syntax-modern
615+
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/hwb
616+
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/lch
617+
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/lab
618+
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/oklch
619+
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/oklab
620+
*/
621+
$tag = '(rgb|hsl|hwb|(?:(?:ok)?(?:lch|lab)))';
622+
623+
// remove alpha channel if it's pointless ..
624+
$content = preg_replace('/' . $tag . '\(\s*([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+\/\s+1(?:(?:\.\d?)*|00%)?\s*\)/i', '$1($2 $3 $4)', $content);
625+
626+
// replace `transparent` with shortcut ..
627+
$content = preg_replace('/' . $tag . '\(\s*[^\s]+\s+[^\s]+\s+[^\s]+\s+\/\s+0(?:[\.0%]*)?\s*\)/i', '#fff0', $content);
628+
629+
return $content;
630+
}
631+
541632
/**
542633
* Shorten CSS font weights.
543634
*

includes/classes/Dependencies/MatthiasMullie/Minify/JS.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,6 @@ class JS extends Minify
122122
*/
123123
protected $operatorsAfter = array();
124124

125-
/**
126-
* {@inheritdoc}
127-
*/
128125
public function __construct()
129126
{
130127
call_user_func_array(array('\\PoweredCache\Dependencies\MatthiasMullie\Minify\\Minify', '__construct'), func_get_args());

includes/classes/Dependencies/MatthiasMullie/Minify/Minify.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ protected function stripMultilineComments()
270270
$minifier = $this;
271271
$callback = function ($match) use ($minifier) {
272272
$count = count($minifier->extracted);
273-
$placeholder = '/*'.$count.'*/';
273+
$placeholder = '/*' . $count . '*/';
274274
$minifier->extracted[$placeholder] = $match[0];
275275

276276
return $placeholder;
@@ -494,14 +494,20 @@ protected function canImportFile($path)
494494
$parsed = parse_url($path);
495495
if (
496496
// file is elsewhere
497-
isset($parsed['host']) ||
497+
isset($parsed['host'])
498498
// file responds to queries (may change, or need to bypass cache)
499-
isset($parsed['query'])
499+
|| isset($parsed['query'])
500500
) {
501501
return false;
502502
}
503503

504-
return strlen($path) < PHP_MAXPATHLEN && @is_file($path) && is_readable($path);
504+
try {
505+
return strlen($path) < PHP_MAXPATHLEN && @is_file($path) && is_readable($path);
506+
}
507+
// catch openbasedir exceptions which are not caught by @ on is_file()
508+
catch (\Exception $e) {
509+
return false;
510+
}
505511
}
506512

507513
/**
@@ -534,9 +540,9 @@ protected function openFileForWriting($path)
534540
protected function writeToFile($handler, $content, $path = '')
535541
{
536542
if (
537-
!is_resource($handler) ||
538-
($result = @fwrite($handler, $content)) === false ||
539-
($result < strlen($content))
543+
!is_resource($handler)
544+
|| ($result = @fwrite($handler, $content)) === false
545+
|| ($result < strlen($content))
540546
) {
541547
throw new IOException('The file "' . $path . '" could not be written to. Check your disk space and file permissions.');
542548
}

includes/classes/Dependencies/Symfony/Polyfill/Php80/composer.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
}
2121
],
2222
"require": {
23-
"php": ">=7.1"
23+
"php": ">=7.2"
2424
},
2525
"autoload": {
2626
"psr-4": { "Symfony\\Polyfill\\Php80\\": "" },
@@ -29,9 +29,6 @@
2929
},
3030
"minimum-stability": "dev",
3131
"extra": {
32-
"branch-alias": {
33-
"dev-main": "1.28-dev"
34-
},
3532
"thanks": {
3633
"name": "symfony/polyfill",
3734
"url": "https://github.com/symfony/polyfill"

includes/classes/Dependencies/voku/helper/AbstractDomParser.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,6 @@ public static function replaceToPreserveHtmlEntities(string $html): string
497497
$linksOld = [];
498498

499499
if (\strpos($html, 'http') !== false) {
500-
501500
// regEx for e.g.: [https://www.domain.de/foo.php?foobar=1&email=lars%40moelleken.org&guid=test1233312&{{foo}}#foo]
502501
$regExUrl = '/(\[?\bhttps?:\/\/[^\s<>]+(?:\(\w+\)|[^[:punct:]\s]|\/|}|]))/i';
503502
\preg_match_all($regExUrl, $html, $linksOld);

includes/classes/Dependencies/voku/helper/AbstractSimpleHtmlDom.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ abstract class AbstractSimpleHtmlDom
2323
'innerhtmlkeep' => 'innerHtmlKeep',
2424
];
2525

26+
/**
27+
* @var string[]
28+
*/
29+
protected static $stringDomNodes = [
30+
'id',
31+
'prefix',
32+
'content'
33+
];
34+
2635
/**
2736
* @var \DOMElement|\DOMNode|null
2837
*/
@@ -167,11 +176,13 @@ public function __set($name, $value)
167176
default:
168177
if ($this->node && \property_exists($this->node, $nameOrig)) {
169178
// INFO: Cannot assign null to property DOMNode::* of type string
170-
if ($nameOrig === 'prefix' || $nameOrig === 'textContent') {
179+
if (in_array($nameOrig, self::$stringDomNodes)) {
171180
$value = (string)$value;
172181
}
173182

174-
return $this->node->{$nameOrig} = $value;
183+
if (!is_null($value)) {
184+
return $this->node->{$nameOrig} = $value;
185+
}
175186
}
176187

177188
return $this->setAttribute($name, $value);

includes/classes/Dependencies/voku/helper/HtmlDomHelper.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
final class HtmlDomHelper
88
{
9-
109
/**
1110
* @param string $html
1211
* @param string $optionStr
@@ -65,7 +64,7 @@ public static function mergeHtmlAttributes(
6564
}
6665

6766
foreach ($attributes as $attributeName => $attributeValue) {
68-
$domElement->setAttribute($attributeName, $attributeValue);
67+
$domElement->setAttribute($attributeName, $attributeValue, true);
6968
}
7069

7170
return $domElement->html();

includes/classes/Dependencies/voku/helper/HtmlDomParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class HtmlDomParser extends AbstractDomParser
7575
* ```php
7676
* protected $specialScriptTags = [
7777
* 'text/html',
78+
* 'text/template',
7879
* 'text/x-custom-template',
7980
* 'text/x-handlebars-template'
8081
* ]
@@ -84,6 +85,7 @@ class HtmlDomParser extends AbstractDomParser
8485
*/
8586
protected $specialScriptTags = [
8687
'text/html',
88+
'text/template',
8789
'text/x-custom-template',
8890
'text/x-handlebars-template',
8991
];
@@ -478,7 +480,6 @@ protected function createDOMDocument(string $html, $libXMLExtraOptions = null, $
478480
}
479481

480482
if ($documentFound === false) {
481-
482483
// UTF-8 hack: http://php.net/manual/en/domdocument.loadhtml.php#95251
483484
$xmlHackUsed = false;
484485
if (\stripos('<?xml', $html) !== 0) {
@@ -1124,7 +1125,6 @@ static function ($value) {
11241125
$html = (string) \preg_replace_callback(
11251126
'/(?<start>(<script [^>]*type=["\']?(?:' . $tags . ')+[^>]*>))(?<innerContent>.*)(?<end><\/script>)/isU',
11261127
function ($matches) {
1127-
11281128
// Check for logic in special script tags, like [<% _.each(tierPrices, function(item, key) { %>],
11291129
// because often this looks like non-valid html in the template itself.
11301130
foreach ($this->templateLogicSyntaxInSpecialScriptTags as $logicSyntaxInSpecialScriptTag) {

0 commit comments

Comments
 (0)