A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/clean-css/clean-css/commit/b6ddc523267fc42cf0f6bd1626a79cad97319e17 below:

Removes level 1 `transform` callback in favor of plugins. · clean-css/clean-css@b6ddc52 · GitHub

File tree Expand file treeCollapse file tree 13 files changed

+72

-124

lines changed

Filter options

Expand file treeCollapse file tree 13 files changed

+72

-124

lines changed Original file line number Diff line number Diff line change

@@ -80,6 +80,7 @@ var output = new CleanCSS(options).minify(input);

80 80

clean-css 5.0 will introduce some breaking changes:

81 81 82 82

* Node.js 6.x and 8.x are officially no longer supported;

83 +

* `transform` callback in level-1 optimizations is removed in favor of new [plugins](#plugins) interface;

83 84 84 85

## Important: 4.0 breaking changes

85 86

@@ -377,8 +378,7 @@ new CleanCSS({

377 378

specialComments: 'all', // denotes a number of /*! ... */ comments preserved; defaults to `all`

378 379

tidyAtRules: true, // controls at-rules (e.g. `@charset`, `@import`) optimizing; defaults to `true`

379 380

tidyBlockScopes: true, // controls block scopes (e.g. `@media`) optimizing; defaults to `true`

380 -

tidySelectors: true, // controls selectors optimizing; defaults to `true`,

381 -

transform: function () {} // defines a callback for fine-grained property optimization; defaults to no-op

381 +

tidySelectors: true, // controls selectors optimizing; defaults to `true`

382 382

}

383 383

}

384 384

});

@@ -448,7 +448,7 @@ In clean-css version 5 and above you can define plugins which run alongside leve

448 448

```js

449 449

var myPlugin = {

450 450

level1: {

451 -

property: function removeRepeatedBackgroundRepeat() {

451 +

property: function removeRepeatedBackgroundRepeat(_rule, property, _options) {

452 452

// So `background-repeat:no-repeat no-repeat` becomes `background-repeat:no-repeat`

453 453

if (property.name == 'background-repeat' && property.value.length == 2 && property.value[0][1] == property.value[1][1]) {

454 454

property.value.pop();

@@ -561,26 +561,7 @@ If you don't provide a callback, then remote `@import`s will be left as is.

561 561 562 562

## How to apply arbitrary transformations to CSS properties?

563 563 564 -

If clean-css doesn't perform a particular property optimization, you can use `transform` callback to apply it:

565 - 566 -

```js

567 -

var source = '.block{background-image:url(/path/to/image.png)}';

568 -

var output = new CleanCSS({

569 -

level: {

570 -

1: {

571 -

transform: function (propertyName, propertyValue, selector /* `selector` available since 4.2.0-pre */) {

572 -

if (propertyName == 'background-image' && propertyValue.indexOf('/path/to') > -1) {

573 -

return propertyValue.replace('/path/to', '../valid/path/to');

574 -

}

575 -

}

576 -

}

577 -

}

578 -

}).minify(source);

579 - 580 -

console.log(output.styles); # => .block{background-image:url(../valid/path/to/image.png)}

581 -

```

582 - 583 -

Note: returning `false` from `transform` callback will drop a property.

564 +

Please see [plugins](#plugins).

584 565 585 566

## How to specify a custom rounding precision?

586 567 Original file line number Diff line number Diff line change

@@ -20,8 +20,6 @@ var formatPosition = require('../../utils/format-position');

20 20 21 21

var serializeRules = require('../../writer/one-time').rules;

22 22 23 -

var IgnoreProperty = 'ignore-property';

24 - 25 23

var CHARSET_TOKEN = '@charset';

26 24

var CHARSET_REGEXP = new RegExp('^' + CHARSET_TOKEN, 'i');

27 25

@@ -56,32 +54,13 @@ function isLegacyFilter(property) {

56 54 57 55

function noop() {}

58 56 59 -

function transformValue(propertyName, propertyValue, rule, options) {

60 -

var selector;

61 -

var transformedValue;

62 - 63 -

if (!options.level[OptimizationLevel.One].transform) {

64 -

return propertyValue;

65 -

}

66 - 67 -

selector = serializeRules(rule);

68 -

transformedValue = options.level[OptimizationLevel.One].transform(propertyName, propertyValue, selector);

69 - 70 -

if (transformedValue === undefined) {

71 -

return propertyValue;

72 -

} else if (transformedValue === false) {

73 -

return IgnoreProperty;

74 -

} else {

75 -

return transformedValue;

76 -

}

77 -

}

78 - 79 57

function optimizeBody(rule, properties, context) {

80 58

var options = context.options;

81 59

var valueOptimizers;

82 60

var property, name, type, value;

83 61

var propertyToken;

84 62

var propertyOptimizer;

63 +

var serializedRule = serializeRules(rule);

85 64

var _properties = wrapForOptimizing(properties, true);

86 65

var pluginValueOptimizers = context.options.plugins.level1Value;

87 66

var pluginPropertyOptimizers = context.options.plugins.level1Property;

@@ -157,20 +136,13 @@ function optimizeBody(rule, properties, context) {

157 136

value = pluginValueOptimizers[k](name, value, options);

158 137

}

159 138 160 -

value = transformValue(name, value, rule, options);

161 - 162 -

if (value === IgnoreProperty) {

163 -

property.unused = true;

164 -

continue propertyLoop;

165 -

}

166 - 167 139

property.value[j][1] = value;

168 140

}

169 141 170 -

propertyOptimizer(property, options);

142 +

propertyOptimizer(serializedRule, property, options);

171 143 172 144

for (j = 0, m = pluginPropertyOptimizers.length; j < m; j++) {

173 -

pluginPropertyOptimizers[j](property, options);

145 +

pluginPropertyOptimizers[j](serializedRule, property, options);

174 146

}

175 147

}

176 148 Original file line number Diff line number Diff line change

@@ -2,7 +2,7 @@ var OptimizationLevel = require('../../../options/optimization-level').Optimizat

2 2 3 3

var plugin = {

4 4

level1: {

5 -

property: function background(property, options) {

5 +

property: function background(_rule, property, options) {

6 6

var values = property.value;

7 7 8 8

if (!options.level[OptimizationLevel.One].optimizeBackground) {

Original file line number Diff line number Diff line change

@@ -2,7 +2,7 @@ var OptimizationLevel = require('../../../options/optimization-level').Optimizat

2 2 3 3

var plugin = {

4 4

level1: {

5 -

property: function borderRadius(property, options) {

5 +

property: function borderRadius(_rule, property, options) {

6 6

var values = property.value;

7 7 8 8

if (!options.level[OptimizationLevel.One].optimizeBorderRadius) {

Original file line number Diff line number Diff line change

@@ -1,6 +1,6 @@

1 1

var plugin = {

2 2

level1: {

3 -

property: function boxShadow(property) {

3 +

property: function boxShadow(_rule, property) {

4 4

var values = property.value;

5 5 6 6

// remove multiple zeros

Original file line number Diff line number Diff line change

@@ -6,7 +6,7 @@ var WHITESPACE_AROUND_EQUALS_PATTERN = / ?= ?/g;

6 6 7 7

var plugin = {

8 8

level1: {

9 -

property: function filter(property, options) {

9 +

property: function filter(_rule, property, options) {

10 10

if (!options.compatibility.properties.ieFilters) {

11 11

return;

12 12

}

Original file line number Diff line number Diff line change

@@ -2,7 +2,7 @@ var OptimizationLevel = require('../../../options/optimization-level').Optimizat

2 2 3 3

var plugin = {

4 4

level1: {

5 -

property: function fontWeight(property, options) {

5 +

property: function fontWeight(_rule, property, options) {

6 6

var value = property.value[0][1];

7 7 8 8

if (!options.level[OptimizationLevel.One].optimizeFontWeight) {

Original file line number Diff line number Diff line change

@@ -2,7 +2,7 @@ var OptimizationLevel = require('../../../options/optimization-level').Optimizat

2 2 3 3

var plugin = {

4 4

level1: {

5 -

property: function margin(property, options) {

5 +

property: function margin(_rule, property, options) {

6 6

var values = property.value;

7 7 8 8

if (!options.level[OptimizationLevel.One].replaceMultipleZeros) {

Original file line number Diff line number Diff line change

@@ -2,7 +2,7 @@ var OptimizationLevel = require('../../../options/optimization-level').Optimizat

2 2 3 3

var plugin = {

4 4

level1: {

5 -

property: function outline(property, options) {

5 +

property: function outline(_rule, property, options) {

6 6

var values = property.value;

7 7 8 8

if (!options.level[OptimizationLevel.One].optimizeOutline) {

Original file line number Diff line number Diff line change

@@ -6,7 +6,7 @@ function isNegative(value) {

6 6 7 7

var plugin = {

8 8

level1: {

9 -

property: function padding(property, options) {

9 +

property: function padding(_rule, property, options) {

10 10

var values = property.value;

11 11 12 12

// remove multiple zeros

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4