251 Commits

Author SHA1 Message Date
Ayumi
0cf6c085b1 Add apng, avif, webp, and woff2 mime types 2021-07-20 13:50:15 +02:00
Roan Kattouw
e3a0356374 Use offsets, reduce string copying to improve performance
Performance improvements in Minify::replace():
- Use offsets when regex matching, instead of substr()ing off the
  processed part of the string
- Perform replacements manually, rather than calling preg_replace() /
  preg_replace_callback() on the entire input string

This dramatically improves performance, especially for inputs with many
things that are replaced at this stage (many strings, comments or
regexes).

The only change noticed by other code is that placeholders like $1 or \2
can no longer be used in Minify::registerPattern(), but no callers were
using this feature anyway, and future callers can use a callback
instead.
2021-01-28 09:01:48 +01:00
Matthias Mullie
8538190f4a Speed up multi-line comment preservation regex 2021-01-27 09:50:14 +01:00
Matthias Mullie
45fd3b0f1d Make test suite pass for all PHP versions 2021-01-06 16:18:10 +01:00
Matthias Mullie
b88dcc64ec Make sure math methods extraction checks for word boundaries
Otherwise, 'max' could be confused with 'minmax'

Fixes #356
2021-01-06 11:20:44 +01:00
Stefan Kalscheuer
3b09a2e01c reverse arguments for implode() call i extractMath()
Fixes regression from 022cd72.
implode() argument order is no longer auto-corrected with PHP 8.
2020-12-27 12:23:53 +01:00
Matthias Mullie
022cd72b68 More robust calc() detection
Fixes #312
2020-12-23 14:34:37 +01:00
Matthias Mullie
21678a360c Fix unsafe use of new static
Fixes #350
2020-12-21 15:10:05 +01:00
Matthias Mullie
26da9bbfc8 Preserve custom properties
Fixes #342
2020-12-21 15:08:36 +01:00
Matthias Mullie
8931f76af2 Also preserve math whitespace in clamp, min, max
Fixes #351
2020-12-21 14:15:47 +01:00
Simon
9ba1b45982 Fix #301 calc() not followed by end of line or semicolon not correctly matched 2020-01-21 12:21:08 -08:00
Rémy Perona
a5cf82753b add multiline flag to extractCalcs pattern 2020-01-21 12:21:08 -08:00
enricodias
e99e51935f Add addFile method
The addFile method will throw an exception if it fails to read a file
2020-01-21 12:15:35 -08:00
Wim Wisselink
47a53716f9 Implode swap parameter order for PHP-7.4 support. 2019-12-19 08:54:47 +01:00
Matthias Mullie
d5acb8ce5b php-cs-fixer 2018-11-27 00:10:39 +01:00
Matthias Mullie
97f118c4c7 Merge branch 'igll-patch-1' 2018-11-27 00:08:46 +01:00
Matthias Mullie
0716502669 Preserve important comments exactly as they are 2018-11-27 00:07:50 +01:00
Matthias Mullie
7d6883bb3d Shorten alpha channel 2018-11-27 00:04:47 +01:00
Matthias Mullie
bb864e00cd Remove whitespace around + and &
Fixes #259
2018-11-27 00:04:46 +01:00
Matthias Mullie
107ed7bc85 Improve regex detection
Fixes #249
Fixes #252
Fixes #253
2018-11-27 00:04:46 +01:00
Rozinko Roman
e52044ac58 move color replace to a shortenColorCodesToHex() function 2018-11-27 00:04:46 +01:00
Rozinko Roman
2dfe767019 add replace 'white' and 'black' to '#fff' and '#000' 2018-11-27 00:04:46 +01:00
Puskás Zsolt
ee023207c5 preserve important comments 2018-11-27 00:04:46 +01:00
Matthias Mullie
2d13b7b851 Preserve important comments exactly as they are 2018-11-27 00:01:41 +01:00
Matthias Mullie
ea20ad3cbc Shorten alpha channel 2018-11-26 23:35:39 +01:00
Matthias Mullie
75bb291978 Remove whitespace around + and &
Fixes #259
2018-11-26 23:35:39 +01:00
Matthias Mullie
cc0eb0cb6d Improve regex detection
Fixes #249
Fixes #252
Fixes #253
2018-11-26 23:35:39 +01:00
Rozinko Roman
d3d13451e1 move color replace to a shortenColorCodesToHex() function 2018-11-26 23:35:39 +01:00
Rozinko Roman
1c6a499a21 add replace 'white' and 'black' to '#fff' and '#000' 2018-11-26 23:35:39 +01:00
Puskás Zsolt
ca7d428102 preserve important comments 2018-08-24 07:35:25 +02:00
igll
0236af7448
Update Minify.php
if (array_key_exists($i, $positions) == false) {
instead of 
if (!isset($positions[$i])) 

in order to avoid "Notice undefined offset"
2018-05-29 09:11:40 +02:00
Kevin Pancake
6d922d0e2a Pass settings to (recursively) referenced files 2018-05-04 08:54:28 +02:00
Matthias Mullie
ab7fea80ce Don't iterate over positions that have already been unset
Fixes #245
2018-04-18 10:50:35 +02:00
Mert Yazıcıoğlu
2e54f8426b Add support for unicode regular expression flag
The regular expression for matching valid JS regular expressions seems to be missing the `u` flag, which is a valid flag to treat a pattern as a sequence of unicode code points.

See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Advanced_searching_with_flags_2
2018-04-04 10:32:45 +02:00
Matthias Mullie
04a37f5434 Make sure $positions & $matches are in sync
Fixes #238
2018-04-04 10:31:39 +02:00
Matthias Mullie
81d3a806b2 Don't leave behind trailing semicolons when moving imports to top
Fixes #240
2018-04-04 10:16:18 +02:00
Matthias Mullie
473896bf31 Allow whitespace between regex & some of the things that can follow it
Fixes #242
2018-04-04 10:06:41 +02:00
Matthias Mullie
121cd3b6eb Some more whitespace stripping
Fixes #232
2018-02-02 12:28:07 +01:00
Matthias Mullie
ba5c2293c1 Ensure minifier always returns a string
Fixes #220
2018-02-02 11:49:22 +01:00
Matthias Mullie
57b38195be Don't import specific files
Fixes #224
2018-02-02 11:21:49 +01:00
Matthias Mullie
4ca8d1e34c Improve regex detection after )
Meanwhile also improves extraction by capturing the exact
regex offset, instead of trying to find it again ourselves.
This will not only be slightly faster, but more accurate
as well, since lookahead/-behind things may be missing
from the match & we could end up finding duplicates that
do not satisfy those assertions...

Fixes #231
2018-02-02 11:03:25 +01:00
Matthias Mullie
1e55fe09e7 Regexes can't span multiple lines
Fixes #234
2018-02-02 09:26:19 +01:00
Matthias Mullie
adfa7ebcd9 Don't go fixing invalid flex attributes
Fixes #235
2018-02-02 08:17:39 +01:00
Matthias Mullie
cb1450437c Improve & optimize regex detection
Fixes #229
2018-01-08 10:47:52 +01:00
Matthias Mullie
023c6bfb19 Ignore unescaped / inside []
Fixes #221
2018-01-01 15:27:09 +01:00
Matthias Mullie
a85f804092 Regex can follow +,-,*,/
Fixes #221
2018-01-01 15:25:15 +01:00
Matthias Mullie
d39132a3be Fix PHP<7 segfault 2017-12-06 13:42:29 +01:00
Matthias Mullie
a370e29897 Add test case for semicolon after do-while 2017-12-06 12:28:58 +01:00
Matthias Mullie
a2024cc406 Strip whitespace after in some cases 2017-12-06 12:21:49 +01:00
Matthias Mullie
f231fbc701 Improve regex detection
The regex to detect regexes is better now, and as a result
I can now take out a bunch of workarounds that were needed
with the earlier flawed regex detection.

Fixes #218
2017-12-06 12:21:18 +01:00