Skip to content

Commit 74fd6f3

Browse files
author
Robin Frischmann
committed
3.0.2 release
1 parent d10d4bb commit 74fd6f3

File tree

98 files changed

+10435
-1984
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+10435
-1984
lines changed

.flowconfig

+4
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33
# Disable module with broken flow types.
44
# .*/node_modules/babylon/*.*
55

6+
.*/node_modules/npm/*.*
7+
.*/node_modules/config-chain/*.*
8+
.*/node_modules/lunr/*.*
9+
610
[version]
711
^0.38.0

Changelog.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## 3.0
44

5+
### 3.0.2
6+
* performance improvements (up to 30% faster)
7+
58
### 3.0.1
69
* performance improvements (~10% faster) ( [#115](https://github.com/rofrischmann/inline-style-prefixer/pull/115) ) ( [#116](https://github.com/rofrischmann/inline-style-prefixer/pull/116) )
710
* ordering prefixed properties correctly ( [#117](https://github.com/rofrischmann/inline-style-prefixer/pull/117) )

benchmark/dynamic/cases/300-dynamic.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Prefixer from '../../packages/301/dynamic'
1+
import Prefixer from '../../packages/300/dynamic'
22

33
const CHROME45 = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36'
44

benchmark/dynamic/cases/301-dynamic.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Prefixer from '../../packages/300/dynamic'
1+
import Prefixer from '../../packages/301/dynamic'
22

33
const CHROME45 = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36'
44

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Prefixer from '../../packages/302/dynamic'
2+
3+
const CHROME45 = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36'
4+
5+
export const dynamic302 = () => {
6+
const styles = {
7+
color: 'red',
8+
display: 'flex',
9+
justifyContent: 'center',
10+
alignItems: 'center',
11+
userSelect: 'none',
12+
fontSize: '12px',
13+
appearance: 'none',
14+
':hover': {
15+
alignSelf: 'flex-start',
16+
transition: '300ms transform linear',
17+
transform: 'rotateX(30deg)',
18+
color: 'blue',
19+
width: ['calc(100% - 50px)', '300px']
20+
}
21+
}
22+
23+
const prefixer = new Prefixer({ userAgent: CHROME45 })
24+
return prefixer.prefix(styles)
25+
}

benchmark/dynamic/cases/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './205-dynamic'
22
export * from './300-dynamic'
33
export * from './301-dynamic'
4+
export * from './302-dynamic'

benchmark/dynamic/index.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Suite } from 'benchmark'
22
import beautifyBenchmark from 'beautify-benchmark'
3-
import { dynamic205, dynamic300, dynamic301 } from './cases'
3+
import { dynamic205, dynamic300, dynamic301, dynamic302 } from './cases'
44

55
export const run = () => {
66
console.log('Running dynamic test.')
@@ -10,18 +10,20 @@ export const run = () => {
1010
testSuite.add('2.0.5', () => dynamic205())
1111
testSuite.add('3.0.0', () => dynamic300())
1212
testSuite.add('3.0.1', () => dynamic301())
13-
13+
testSuite.add('3.0.2', () => dynamic301())
14+
1415
testSuite.on('cycle', (e) => {
1516
beautifyBenchmark.add(e.target)
1617
})
1718

1819
testSuite.on('complete', function () {
1920
beautifyBenchmark.log()
2021
console.log(`Fastest is: ${this.filter('fastest').map('name')}\n`)
21-
22-
console.log(
23-
`Improvement: ${Math.round(this[this.length -1].hz / this[this.length - 2].hz * 100) / 100}x faster`
24-
)
22+
23+
console.log(
24+
`Improvement: ${Math.round(this[this.length - 1].hz / this[this.length - 2].hz * 100) /
25+
100}x faster`
26+
)
2527
})
2628

2729
return testSuite.run({ async: true })
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
7+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8+
9+
exports.default = createPrefixer;
10+
11+
var _getBrowserInformation = require('../utils/getBrowserInformation');
12+
13+
var _getBrowserInformation2 = _interopRequireDefault(_getBrowserInformation);
14+
15+
var _getPrefixedKeyframes = require('../utils/getPrefixedKeyframes');
16+
17+
var _getPrefixedKeyframes2 = _interopRequireDefault(_getPrefixedKeyframes);
18+
19+
var _capitalizeString = require('../utils/capitalizeString');
20+
21+
var _capitalizeString2 = _interopRequireDefault(_capitalizeString);
22+
23+
var _addNewValuesOnly = require('../utils/addNewValuesOnly');
24+
25+
var _addNewValuesOnly2 = _interopRequireDefault(_addNewValuesOnly);
26+
27+
var _isObject = require('../utils/isObject');
28+
29+
var _isObject2 = _interopRequireDefault(_isObject);
30+
31+
var _prefixValue = require('../utils/prefixValue');
32+
33+
var _prefixValue2 = _interopRequireDefault(_prefixValue);
34+
35+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
36+
37+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
38+
39+
function createPrefixer(_ref) {
40+
var prefixMap = _ref.prefixMap,
41+
plugins = _ref.plugins;
42+
var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (style) {
43+
return style;
44+
};
45+
46+
return function () {
47+
/**
48+
* Instantiante a new prefixer
49+
* @param {string} userAgent - userAgent to gather prefix information according to caniuse.com
50+
* @param {string} keepUnprefixed - keeps unprefixed properties and values
51+
*/
52+
function Prefixer() {
53+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
54+
55+
_classCallCheck(this, Prefixer);
56+
57+
var defaultUserAgent = typeof navigator !== 'undefined' ? navigator.userAgent : undefined;
58+
59+
this._userAgent = options.userAgent || defaultUserAgent;
60+
this._keepUnprefixed = options.keepUnprefixed || false;
61+
62+
if (this._userAgent) {
63+
this._browserInfo = (0, _getBrowserInformation2.default)(this._userAgent);
64+
}
65+
66+
// Checks if the userAgent was resolved correctly
67+
if (this._browserInfo && this._browserInfo.cssPrefix) {
68+
this.prefixedKeyframes = (0, _getPrefixedKeyframes2.default)(this._browserInfo.browserName, this._browserInfo.browserVersion, this._browserInfo.cssPrefix);
69+
} else {
70+
this._useFallback = true;
71+
return false;
72+
}
73+
74+
var prefixData = this._browserInfo.browserName && prefixMap[this._browserInfo.browserName];
75+
if (prefixData) {
76+
this._requiresPrefix = {};
77+
78+
for (var property in prefixData) {
79+
if (prefixData[property] >= this._browserInfo.browserVersion) {
80+
this._requiresPrefix[property] = true;
81+
}
82+
}
83+
84+
this._hasPropsRequiringPrefix = Object.keys(this._requiresPrefix).length > 0;
85+
} else {
86+
this._useFallback = true;
87+
}
88+
89+
this._metaData = {
90+
browserVersion: this._browserInfo.browserVersion,
91+
browserName: this._browserInfo.browserName,
92+
cssPrefix: this._browserInfo.cssPrefix,
93+
jsPrefix: this._browserInfo.jsPrefix,
94+
keepUnprefixed: this._keepUnprefixed,
95+
requiresPrefix: this._requiresPrefix
96+
};
97+
}
98+
99+
_createClass(Prefixer, [{
100+
key: 'prefix',
101+
value: function prefix(style) {
102+
// use static prefixer as fallback if userAgent can not be resolved
103+
if (this._useFallback) {
104+
return fallback(style);
105+
}
106+
107+
// only add prefixes if needed
108+
if (!this._hasPropsRequiringPrefix) {
109+
return style;
110+
}
111+
112+
return this._prefixStyle(style);
113+
}
114+
}, {
115+
key: '_prefixStyle',
116+
value: function _prefixStyle(style) {
117+
for (var property in style) {
118+
var value = style[property];
119+
120+
// handle nested objects
121+
if ((0, _isObject2.default)(value)) {
122+
style[property] = this.prefix(value);
123+
// handle array values
124+
} else if (Array.isArray(value)) {
125+
var combinedValue = [];
126+
127+
for (var i = 0, len = value.length; i < len; ++i) {
128+
var processedValue = (0, _prefixValue2.default)(plugins, property, value[i], style, this._metaData);
129+
(0, _addNewValuesOnly2.default)(combinedValue, processedValue || value[i]);
130+
}
131+
132+
// only modify the value if it was touched
133+
// by any plugin to prevent unnecessary mutations
134+
if (combinedValue.length > 0) {
135+
style[property] = combinedValue;
136+
}
137+
} else {
138+
var _processedValue = (0, _prefixValue2.default)(plugins, property, value, style, this._metaData);
139+
140+
// only modify the value if it was touched
141+
// by any plugin to prevent unnecessary mutations
142+
if (_processedValue) {
143+
style[property] = _processedValue;
144+
}
145+
146+
// add prefixes to properties
147+
if (this._requiresPrefix.hasOwnProperty(property)) {
148+
style[this._browserInfo.jsPrefix + (0, _capitalizeString2.default)(property)] = value;
149+
if (!this._keepUnprefixed) {
150+
delete style[property];
151+
}
152+
}
153+
}
154+
}
155+
156+
return style;
157+
}
158+
159+
/**
160+
* Returns a prefixed version of the style object using all vendor prefixes
161+
* @param {Object} styles - Style object that gets prefixed properties added
162+
* @returns {Object} - Style object with prefixed properties and values
163+
*/
164+
165+
}], [{
166+
key: 'prefixAll',
167+
value: function prefixAll(styles) {
168+
return fallback(styles);
169+
}
170+
}]);
171+
172+
return Prefixer;
173+
}();
174+
}
175+
module.exports = exports['default'];

0 commit comments

Comments
 (0)