-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robin Frischmann
committed
Mar 13, 2017
1 parent
d10d4bb
commit 74fd6f3
Showing
98 changed files
with
10,435 additions
and
1,984 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Prefixer from '../../packages/302/dynamic' | ||
|
||
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' | ||
|
||
export const dynamic302 = () => { | ||
const styles = { | ||
color: 'red', | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
userSelect: 'none', | ||
fontSize: '12px', | ||
appearance: 'none', | ||
':hover': { | ||
alignSelf: 'flex-start', | ||
transition: '300ms transform linear', | ||
transform: 'rotateX(30deg)', | ||
color: 'blue', | ||
width: ['calc(100% - 50px)', '300px'] | ||
} | ||
} | ||
|
||
const prefixer = new Prefixer({ userAgent: CHROME45 }) | ||
return prefixer.prefix(styles) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './205-dynamic' | ||
export * from './300-dynamic' | ||
export * from './301-dynamic' | ||
export * from './302-dynamic' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
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; }; }(); | ||
|
||
exports.default = createPrefixer; | ||
|
||
var _getBrowserInformation = require('../utils/getBrowserInformation'); | ||
|
||
var _getBrowserInformation2 = _interopRequireDefault(_getBrowserInformation); | ||
|
||
var _getPrefixedKeyframes = require('../utils/getPrefixedKeyframes'); | ||
|
||
var _getPrefixedKeyframes2 = _interopRequireDefault(_getPrefixedKeyframes); | ||
|
||
var _capitalizeString = require('../utils/capitalizeString'); | ||
|
||
var _capitalizeString2 = _interopRequireDefault(_capitalizeString); | ||
|
||
var _addNewValuesOnly = require('../utils/addNewValuesOnly'); | ||
|
||
var _addNewValuesOnly2 = _interopRequireDefault(_addNewValuesOnly); | ||
|
||
var _isObject = require('../utils/isObject'); | ||
|
||
var _isObject2 = _interopRequireDefault(_isObject); | ||
|
||
var _prefixValue = require('../utils/prefixValue'); | ||
|
||
var _prefixValue2 = _interopRequireDefault(_prefixValue); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
|
||
function createPrefixer(_ref) { | ||
var prefixMap = _ref.prefixMap, | ||
plugins = _ref.plugins; | ||
var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (style) { | ||
return style; | ||
}; | ||
|
||
return function () { | ||
/** | ||
* Instantiante a new prefixer | ||
* @param {string} userAgent - userAgent to gather prefix information according to caniuse.com | ||
* @param {string} keepUnprefixed - keeps unprefixed properties and values | ||
*/ | ||
function Prefixer() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
|
||
_classCallCheck(this, Prefixer); | ||
|
||
var defaultUserAgent = typeof navigator !== 'undefined' ? navigator.userAgent : undefined; | ||
|
||
this._userAgent = options.userAgent || defaultUserAgent; | ||
this._keepUnprefixed = options.keepUnprefixed || false; | ||
|
||
if (this._userAgent) { | ||
this._browserInfo = (0, _getBrowserInformation2.default)(this._userAgent); | ||
} | ||
|
||
// Checks if the userAgent was resolved correctly | ||
if (this._browserInfo && this._browserInfo.cssPrefix) { | ||
this.prefixedKeyframes = (0, _getPrefixedKeyframes2.default)(this._browserInfo.browserName, this._browserInfo.browserVersion, this._browserInfo.cssPrefix); | ||
} else { | ||
this._useFallback = true; | ||
return false; | ||
} | ||
|
||
var prefixData = this._browserInfo.browserName && prefixMap[this._browserInfo.browserName]; | ||
if (prefixData) { | ||
this._requiresPrefix = {}; | ||
|
||
for (var property in prefixData) { | ||
if (prefixData[property] >= this._browserInfo.browserVersion) { | ||
this._requiresPrefix[property] = true; | ||
} | ||
} | ||
|
||
this._hasPropsRequiringPrefix = Object.keys(this._requiresPrefix).length > 0; | ||
} else { | ||
this._useFallback = true; | ||
} | ||
|
||
this._metaData = { | ||
browserVersion: this._browserInfo.browserVersion, | ||
browserName: this._browserInfo.browserName, | ||
cssPrefix: this._browserInfo.cssPrefix, | ||
jsPrefix: this._browserInfo.jsPrefix, | ||
keepUnprefixed: this._keepUnprefixed, | ||
requiresPrefix: this._requiresPrefix | ||
}; | ||
} | ||
|
||
_createClass(Prefixer, [{ | ||
key: 'prefix', | ||
value: function prefix(style) { | ||
// use static prefixer as fallback if userAgent can not be resolved | ||
if (this._useFallback) { | ||
return fallback(style); | ||
} | ||
|
||
// only add prefixes if needed | ||
if (!this._hasPropsRequiringPrefix) { | ||
return style; | ||
} | ||
|
||
return this._prefixStyle(style); | ||
} | ||
}, { | ||
key: '_prefixStyle', | ||
value: function _prefixStyle(style) { | ||
for (var property in style) { | ||
var value = style[property]; | ||
|
||
// handle nested objects | ||
if ((0, _isObject2.default)(value)) { | ||
style[property] = this.prefix(value); | ||
// handle array values | ||
} else if (Array.isArray(value)) { | ||
var combinedValue = []; | ||
|
||
for (var i = 0, len = value.length; i < len; ++i) { | ||
var processedValue = (0, _prefixValue2.default)(plugins, property, value[i], style, this._metaData); | ||
(0, _addNewValuesOnly2.default)(combinedValue, processedValue || value[i]); | ||
} | ||
|
||
// only modify the value if it was touched | ||
// by any plugin to prevent unnecessary mutations | ||
if (combinedValue.length > 0) { | ||
style[property] = combinedValue; | ||
} | ||
} else { | ||
var _processedValue = (0, _prefixValue2.default)(plugins, property, value, style, this._metaData); | ||
|
||
// only modify the value if it was touched | ||
// by any plugin to prevent unnecessary mutations | ||
if (_processedValue) { | ||
style[property] = _processedValue; | ||
} | ||
|
||
// add prefixes to properties | ||
if (this._requiresPrefix.hasOwnProperty(property)) { | ||
style[this._browserInfo.jsPrefix + (0, _capitalizeString2.default)(property)] = value; | ||
if (!this._keepUnprefixed) { | ||
delete style[property]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return style; | ||
} | ||
|
||
/** | ||
* Returns a prefixed version of the style object using all vendor prefixes | ||
* @param {Object} styles - Style object that gets prefixed properties added | ||
* @returns {Object} - Style object with prefixed properties and values | ||
*/ | ||
|
||
}], [{ | ||
key: 'prefixAll', | ||
value: function prefixAll(styles) { | ||
return fallback(styles); | ||
} | ||
}]); | ||
|
||
return Prefixer; | ||
}(); | ||
} | ||
module.exports = exports['default']; |
Oops, something went wrong.