forked from FortAwesome/react-fontawesome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
413 lines (324 loc) · 11.6 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@fortawesome/fontawesome-svg-core'), require('prop-types'), require('react')) :
typeof define === 'function' && define.amd ? define(['exports', '@fortawesome/fontawesome-svg-core', 'prop-types', 'react'], factory) :
(factory((global['react-fontawesome'] = {}),global.FontAwesome,global.PropTypes,global.React));
}(this, (function (exports,fontawesomeSvgCore,PropTypes,React) { 'use strict';
PropTypes = PropTypes && PropTypes.hasOwnProperty('default') ? PropTypes['default'] : PropTypes;
React = React && React.hasOwnProperty('default') ? React['default'] : React;
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
var humps = createCommonjsModule(function (module) {
(function(global) {
var _processKeys = function(convert, obj, options) {
if(!_isObject(obj) || _isDate(obj) || _isRegExp(obj) || _isBoolean(obj) || _isFunction(obj)) {
return obj;
}
var output,
i = 0,
l = 0;
if(_isArray(obj)) {
output = [];
for(l=obj.length; i<l; i++) {
output.push(_processKeys(convert, obj[i], options));
}
}
else {
output = {};
for(var key in obj) {
if(Object.prototype.hasOwnProperty.call(obj, key)) {
output[convert(key, options)] = _processKeys(convert, obj[key], options);
}
}
}
return output;
};
// String conversion methods
var separateWords = function(string, options) {
options = options || {};
var separator = options.separator || '_';
var split = options.split || /(?=[A-Z])/;
return string.split(split).join(separator);
};
var camelize = function(string) {
if (_isNumerical(string)) {
return string;
}
string = string.replace(/[\-_\s]+(.)?/g, function(match, chr) {
return chr ? chr.toUpperCase() : '';
});
// Ensure 1st char is always lowercase
return string.substr(0, 1).toLowerCase() + string.substr(1);
};
var pascalize = function(string) {
var camelized = camelize(string);
// Ensure 1st char is always uppercase
return camelized.substr(0, 1).toUpperCase() + camelized.substr(1);
};
var decamelize = function(string, options) {
return separateWords(string, options).toLowerCase();
};
// Utilities
// Taken from Underscore.js
var toString = Object.prototype.toString;
var _isFunction = function(obj) {
return typeof(obj) === 'function';
};
var _isObject = function(obj) {
return obj === Object(obj);
};
var _isArray = function(obj) {
return toString.call(obj) == '[object Array]';
};
var _isDate = function(obj) {
return toString.call(obj) == '[object Date]';
};
var _isRegExp = function(obj) {
return toString.call(obj) == '[object RegExp]';
};
var _isBoolean = function(obj) {
return toString.call(obj) == '[object Boolean]';
};
// Performant way to determine if obj coerces to a number
var _isNumerical = function(obj) {
obj = obj - 0;
return obj === obj;
};
// Sets up function which handles processing keys
// allowing the convert function to be modified by a callback
var _processor = function(convert, options) {
var callback = options && 'process' in options ? options.process : options;
if(typeof(callback) !== 'function') {
return convert;
}
return function(string, options) {
return callback(string, convert, options);
}
};
var humps = {
camelize: camelize,
decamelize: decamelize,
pascalize: pascalize,
depascalize: decamelize,
camelizeKeys: function(object, options) {
return _processKeys(_processor(camelize, options), object);
},
decamelizeKeys: function(object, options) {
return _processKeys(_processor(decamelize, options), object, options);
},
pascalizeKeys: function(object, options) {
return _processKeys(_processor(pascalize, options), object);
},
depascalizeKeys: function () {
return this.decamelizeKeys.apply(this, arguments);
}
};
if (typeof undefined === 'function' && undefined.amd) {
undefined(humps);
} else if ('object' !== 'undefined' && module.exports) {
module.exports = humps;
} else {
global.humps = humps;
}
})(commonjsGlobal);
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
var defineProperty = function (obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
};
var _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
var objectWithoutProperties = function (obj, keys) {
var target = {};
for (var i in obj) {
if (keys.indexOf(i) >= 0) continue;
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
target[i] = obj[i];
}
return target;
};
var toConsumableArray = function (arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
return arr2;
} else {
return Array.from(arr);
}
};
function capitalize(val) {
return val.charAt(0).toUpperCase() + val.slice(1);
}
function styleToObject(style) {
return style.split(';').map(function (s) {
return s.trim();
}).filter(function (s) {
return s;
}).reduce(function (acc, pair) {
var i = pair.indexOf(':');
var prop = humps.camelize(pair.slice(0, i));
var value = pair.slice(i + 1).trim();
prop.startsWith('webkit') ? acc[capitalize(prop)] = value : acc[prop] = value;
return acc;
}, {});
}
function convert(createElement, element) {
var extraProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var children = (element.children || []).map(convert.bind(null, createElement));
var mixins = Object.keys(element.attributes || {}).reduce(function (acc, key) {
var val = element.attributes[key];
switch (key) {
case 'class':
acc.attrs['className'] = val;
delete element.attributes['class'];
break;
case 'style':
acc.attrs['style'] = styleToObject(val);
break;
default:
if (key.indexOf('aria-') === 0 || key.indexOf('data-') === 0) {
acc.attrs[key.toLowerCase()] = val;
} else {
acc.attrs[humps.camelize(key)] = val;
}
}
return acc;
}, { attrs: {} });
var _extraProps$style = extraProps.style,
existingStyle = _extraProps$style === undefined ? {} : _extraProps$style,
remaining = objectWithoutProperties(extraProps, ['style']);
mixins.attrs['style'] = _extends({}, mixins.attrs['style'], existingStyle);
return createElement.apply(undefined, [element.tag, _extends({}, mixins.attrs, remaining)].concat(toConsumableArray(children)));
}
var PRODUCTION = false;
try {
PRODUCTION = process.env.NODE_ENV === 'production';
} catch (e) {}
function log () {
if (!PRODUCTION && console && typeof console.error === 'function') {
var _console;
(_console = console).error.apply(_console, arguments);
}
}
function objectWithKey(key, value) {
return Array.isArray(value) && value.length > 0 || !Array.isArray(value) && value ? defineProperty({}, key, value) : {};
}
function classList(props) {
var _classes;
var classes = (_classes = {
'fa-spin': props.spin,
'fa-pulse': props.pulse,
'fa-fw': props.fixedWidth,
'fa-inverse': props.inverse,
'fa-border': props.border,
'fa-li': props.listItem,
'fa-flip-horizontal': props.flip === 'horizontal' || props.flip === 'both',
'fa-flip-vertical': props.flip === 'vertical' || props.flip === 'both'
}, defineProperty(_classes, 'fa-' + props.size, props.size !== null), defineProperty(_classes, 'fa-rotate-' + props.rotation, props.rotation !== null), defineProperty(_classes, 'fa-pull-' + props.pull, props.pull !== null), _classes);
return Object.keys(classes).map(function (key) {
return classes[key] ? key : null;
}).filter(function (key) {
return key;
});
}
function normalizeIconArgs(icon) {
if (icon === null) {
return null;
}
if ((typeof icon === 'undefined' ? 'undefined' : _typeof(icon)) === 'object' && icon.prefix && icon.iconName) {
return icon;
}
if (Array.isArray(icon) && icon.length === 2) {
return { prefix: icon[0], iconName: icon[1] };
}
if (typeof icon === 'string') {
return { prefix: 'fas', iconName: icon };
}
}
function FontAwesomeIcon(props) {
var iconArgs = props.icon,
maskArgs = props.mask,
symbol = props.symbol,
className = props.className;
var iconLookup = normalizeIconArgs(iconArgs);
var classes = objectWithKey('classes', [].concat(toConsumableArray(classList(props)), toConsumableArray(className.split(' '))));
var transform = objectWithKey('transform', typeof props.transform === 'string' ? fontawesomeSvgCore.parse.transform(props.transform) : props.transform);
var mask = objectWithKey('mask', normalizeIconArgs(maskArgs));
var renderedIcon = fontawesomeSvgCore.icon(iconLookup, _extends({}, classes, transform, mask, {
symbol: symbol
}));
if (!renderedIcon) {
log('Could not find icon', iconLookup);
return null;
}
var abstract = renderedIcon.abstract;
var extraProps = {};
Object.keys(props).forEach(function (key) {
if (!FontAwesomeIcon.defaultProps.hasOwnProperty(key)) {
extraProps[key] = props[key];
}
});
return convertCurry(abstract[0], extraProps);
}
FontAwesomeIcon.displayName = 'FontAwesomeIcon';
FontAwesomeIcon.propTypes = {
border: PropTypes.bool,
className: PropTypes.string,
mask: PropTypes.oneOfType([PropTypes.object, PropTypes.array, PropTypes.string]),
fixedWidth: PropTypes.bool,
inverse: PropTypes.bool,
flip: PropTypes.oneOf(['horizontal', 'vertical', 'both']),
icon: PropTypes.oneOfType([PropTypes.object, PropTypes.array, PropTypes.string]),
listItem: PropTypes.bool,
pull: PropTypes.oneOf(['right', 'left']),
pulse: PropTypes.bool,
rotation: PropTypes.oneOf([90, 180, 270]),
size: PropTypes.oneOf(['lg', 'xs', 'sm', '1x', '2x', '3x', '4x', '5x', '6x', '7x', '8x', '9x', '10x']),
spin: PropTypes.bool,
symbol: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
transform: PropTypes.oneOfType([PropTypes.string, PropTypes.object])
};
FontAwesomeIcon.defaultProps = {
border: false,
className: '',
mask: null,
fixedWidth: false,
inverse: false,
flip: null,
icon: null,
listItem: false,
pull: null,
pulse: false,
rotation: null,
size: null,
spin: false,
symbol: false,
transform: null
};
var convertCurry = convert.bind(null, React.createElement);
exports.FontAwesomeIcon = FontAwesomeIcon;
Object.defineProperty(exports, '__esModule', { value: true });
})));