Skip to content

Commit

Permalink
get rid of flow
Browse files Browse the repository at this point in the history
  • Loading branch information
robinweser committed Nov 16, 2022
1 parent 82154d0 commit 6d59fdb
Show file tree
Hide file tree
Showing 50 changed files with 1,474 additions and 96 deletions.
19 changes: 19 additions & 0 deletions benchmark/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"presets": [
[
"es2015",
{
"modules": "commonjs"
}
],
"stage-0",
"react"
],
"env": {
"commonjs": {
"plugins": [
"transform-es2015-modules-commonjs"
]
}
}
}
67 changes: 67 additions & 0 deletions benchmark/packages/700/createPrefixer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = createPrefixer;

var _prefixProperty = require('./utils/prefixProperty');

var _prefixProperty2 = _interopRequireDefault(_prefixProperty);

var _prefixValue = require('./utils/prefixValue');

var _prefixValue2 = _interopRequireDefault(_prefixValue);

var _addNewValuesOnly = require('./utils/addNewValuesOnly');

var _addNewValuesOnly2 = _interopRequireDefault(_addNewValuesOnly);

var _isObject = require('./utils/isObject');

var _isObject2 = _interopRequireDefault(_isObject);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function createPrefixer(_ref) {
var prefixMap = _ref.prefixMap,
plugins = _ref.plugins;

return function prefix(style) {
for (var property in style) {
var value = style[property];

// handle nested objects
if ((0, _isObject2.default)(value)) {
style[property] = 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, prefixMap);

(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, prefixMap);

// only modify the value if it was touched
// by any plugin to prevent unnecessary mutations
if (_processedValue) {
style[property] = _processedValue;
}

style = (0, _prefixProperty2.default)(prefixMap, property, style);
}
}

return style;
};
}
102 changes: 102 additions & 0 deletions benchmark/packages/700/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
'use strict'

Object.defineProperty(exports, '__esModule', {
value: true,
})

var _backgroundClip = require('./plugins/backgroundClip')

var _backgroundClip2 = _interopRequireDefault(_backgroundClip)

var _crossFade = require('./plugins/crossFade')

var _crossFade2 = _interopRequireDefault(_crossFade)

var _gradient = require('./plugins/gradient')

var _gradient2 = _interopRequireDefault(_gradient)

var _imageSet = require('./plugins/imageSet')

var _imageSet2 = _interopRequireDefault(_imageSet)

var _sizing = require('./plugins/sizing')

var _sizing2 = _interopRequireDefault(_sizing)

var _transition = require('./plugins/transition')

var _transition2 = _interopRequireDefault(_transition)

function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj }
}

var w = ['Webkit']
var m = ['Moz']
var ms = ['ms']
var wm = ['Webkit', 'Moz']
var wms = ['Webkit', 'ms']
var wmms = ['Webkit', 'Moz', 'ms']

exports.default = {
plugins: [
_backgroundClip2.default,
_crossFade2.default,
_gradient2.default,
_imageSet2.default,
_sizing2.default,
_transition2.default,
],
prefixMap: {
appearance: wmms,
textEmphasisPosition: wms,
textEmphasis: wms,
textEmphasisStyle: wms,
textEmphasisColor: wms,
boxDecorationBreak: wms,
maskImage: wms,
maskMode: wms,
maskRepeat: wms,
maskPosition: wms,
maskClip: wms,
maskOrigin: wms,
maskSize: wms,
maskComposite: wms,
mask: wms,
maskBorderSource: wms,
maskBorderMode: wms,
maskBorderSlice: wms,
maskBorderWidth: wms,
maskBorderOutset: wms,
maskBorderRepeat: wms,
maskBorder: wms,
maskType: wms,
userSelect: wms,
backdropFilter: w,
clipPath: w,
hyphens: wms,
textOrientation: w,
tabSize: m,
wrapFlow: ms,
wrapThrough: ms,
wrapMargin: ms,
scrollSnapType: ms,
scrollSnapPointsX: ms,
scrollSnapPointsY: ms,
scrollSnapDestination: ms,
scrollSnapCoordinate: ms,
textSizeAdjust: ['ms', 'Webkit'],
flowInto: ms,
flowFrom: ms,
breakBefore: ms,
breakAfter: ms,
breakInside: ms,
regionFragment: ms,
fontKerning: w,
textDecorationStyle: w,
textDecorationSkip: w,
textDecorationLine: w,
textDecorationColor: w,
},
}
32 changes: 32 additions & 0 deletions benchmark/packages/700/generator/generatePluginList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getRecommendedPlugins;

var _pluginMap = require('./maps/pluginMap');

var _pluginMap2 = _interopRequireDefault(_pluginMap);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function getRecommendedPlugins(browserList) {
var recommendedPlugins = {};

for (var plugin in _pluginMap2.default) {
var browserSupportByPlugin = _pluginMap2.default[plugin];

for (var browser in browserSupportByPlugin) {
if (browserList.hasOwnProperty(browser)) {
var browserVersion = browserSupportByPlugin[browser];

if (browserList[browser] < browserVersion) {
recommendedPlugins[plugin] = true;
}
}
}
}

return Object.keys(recommendedPlugins);
}
86 changes: 86 additions & 0 deletions benchmark/packages/700/generator/generatePrefixMap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = generatePrefixMap;

var _caniuseApi = require('caniuse-api');

var _propertyMap = require('./maps/propertyMap');

var _propertyMap2 = _interopRequireDefault(_propertyMap);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var prefixBrowserMap = {
chrome: 'Webkit',
safari: 'Webkit',
firefox: 'Moz',
opera: 'Webkit',
ie: 'ms',
edge: 'ms',
ios_saf: 'Webkit',
android: 'Webkit',
and_chr: 'Webkit',
and_uc: 'Webkit',
op_mini: 'Webkit'

// remove flexprops from IE
};var flexPropsIE = ['alignContent', 'alignSelf', 'alignItems', 'justifyContent', 'order', 'flexGrow', 'flexShrink', 'flexBasis'];

function filterAndRemoveIfEmpty(map, property, filter) {
if (map[property]) {
map[property] = map[property].filter(filter);

if (map[property].length === 0) {
delete map[property];
}
}
}

function generatePrefixMap(browserList) {
var prefixMap = {};

for (var browser in prefixBrowserMap) {
var prefix = prefixBrowserMap[browser];

for (var keyword in _propertyMap2.default) {
var keywordProperties = [].concat(_propertyMap2.default[keyword]);
var versions = (0, _caniuseApi.getSupport)(keyword);

for (var i = 0, len = keywordProperties.length; i < len; ++i) {
if (versions[browser].x >= browserList[browser]) {
var property = keywordProperties[i];
if (!prefixMap[property]) {
prefixMap[property] = [];
}

if (prefixMap[property].indexOf(prefix) === -1) {
prefixMap[property].push(prefix);
}
}
}
}
}

// remove flexProps from IE and Firefox due to alternative syntax
for (var _i = 0, _len = flexPropsIE.length; _i < _len; ++_i) {
filterAndRemoveIfEmpty(prefixMap, flexPropsIE[_i], function (prefix) {
return prefix !== 'ms' && prefix !== 'Moz';
});
}

// remove transition from Moz and Webkit as they are handled
// specially by the transition plugins
filterAndRemoveIfEmpty(prefixMap, 'transition', function (prefix) {
return prefix !== 'Moz' && prefix !== 'Webkit';
});

// remove WebkitFlexDirection as it does not exist
filterAndRemoveIfEmpty(prefixMap, 'flexDirection', function (prefix) {
return prefix !== 'Moz';
});

return prefixMap;
}
Loading

0 comments on commit 6d59fdb

Please sign in to comment.