-
Notifications
You must be signed in to change notification settings - Fork 133
/
index.js
634 lines (594 loc) · 20.1 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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@fortawesome/fontawesome-svg-core'), require('vue')) :
typeof define === 'function' && define.amd ? define(['exports', '@fortawesome/fontawesome-svg-core', 'vue'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["vue-fontawesome"] = {}, global.FontAwesome, global.vue));
})(this, (function (exports, fontawesomeSvgCore, vue) { 'use strict';
function ownKeys(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
r && (o = o.filter(function (r) {
return Object.getOwnPropertyDescriptor(e, r).enumerable;
})), t.push.apply(t, o);
}
return t;
}
function _objectSpread2(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
_defineProperty(e, r, t[r]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
});
}
return e;
}
function _toPrimitive(t, r) {
if ("object" != typeof t || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != typeof i) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == typeof i ? i : i + "";
}
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
function _defineProperty(obj, key, value) {
key = _toPropertyKey(key);
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
}
return target;
}
function _objectWithoutProperties(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for (i = 0; i < sourceSymbolKeys.length; i++) {
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
var humps$1 = {exports: {}};
(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 (module.exports) {
module.exports = humps;
} else {
global.humps = humps;
}
})(commonjsGlobal);
} (humps$1));
var humps = humps$1.exports;
var _excluded = ["class", "style"];
/**
* Converts a CSS style into a plain Javascript object.
* @param {String} style The style to converts into a plain Javascript object.
* @returns {Object}
*/
function styleToObject(style) {
return style.split(';').map(function (s) {
return s.trim();
}).filter(function (s) {
return s;
}).reduce(function (output, pair) {
var idx = pair.indexOf(':');
var prop = humps.camelize(pair.slice(0, idx));
var value = pair.slice(idx + 1).trim();
output[prop] = value;
return output;
}, {});
}
/**
* Converts a CSS class list into a plain Javascript object.
* @param {Array<String>} classes The class list to convert.
* @returns {Object}
*/
function classToObject(classes) {
return classes.split(/\s+/).reduce(function (output, className) {
output[className] = true;
return output;
}, {});
}
/**
* Converts a FontAwesome abstract element of an icon into a Vue VNode.
* @param {AbstractElement | String} abstractElement The element to convert.
* @param {Object} props The user-defined props.
* @param {Object} attrs The user-defined native HTML attributes.
* @returns {VNode}
*/
function convert(abstractElement) {
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var attrs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
// If the abstract element is a string, we'll just return a string render function
if (typeof abstractElement === 'string') {
return abstractElement;
}
// Converting abstract element children into Vue VNodes
var children = (abstractElement.children || []).map(function (child) {
return convert(child);
});
// Converting abstract element attributes into valid Vue format
var mixins = Object.keys(abstractElement.attributes || {}).reduce(function (mixins, key) {
var value = abstractElement.attributes[key];
switch (key) {
case 'class':
mixins.class = classToObject(value);
break;
case 'style':
mixins.style = styleToObject(value);
break;
default:
mixins.attrs[key] = value;
}
return mixins;
}, {
attrs: {},
class: {},
style: {}
});
// Now, we'll return the VNode
attrs.class;
var _attrs$style = attrs.style,
aStyle = _attrs$style === void 0 ? {} : _attrs$style,
otherAttrs = _objectWithoutProperties(attrs, _excluded);
return vue.h(abstractElement.tag, _objectSpread2(_objectSpread2(_objectSpread2({}, props), {}, {
class: mixins.class,
style: _objectSpread2(_objectSpread2({}, mixins.style), aStyle)
}, mixins.attrs), otherAttrs), 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-border': props.border,
'fa-li': props.listItem,
'fa-inverse': props.inverse,
'fa-flip': props.flip === true,
'fa-flip-horizontal': props.flip === 'horizontal' || props.flip === 'both',
'fa-flip-vertical': props.flip === 'vertical' || props.flip === 'both'
}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_classes, "fa-".concat(props.size), props.size !== null), "fa-rotate-".concat(props.rotation), props.rotation !== null), "fa-pull-".concat(props.pull), props.pull !== null), 'fa-swap-opacity', props.swapOpacity), 'fa-bounce', props.bounce), 'fa-shake', props.shake), 'fa-beat', props.beat), 'fa-fade', props.fade), 'fa-beat-fade', props.beatFade), 'fa-flash', props.flash), _defineProperty(_defineProperty(_classes, 'fa-spin-pulse', props.spinPulse), 'fa-spin-reverse', props.spinReverse));
return Object.keys(classes).map(function (key) {
return classes[key] ? key : null;
}).filter(function (key) {
return key;
});
}
function normalizeIconArgs(icon) {
if (icon && _typeof(icon) === 'object' && icon.prefix && icon.iconName && icon.icon) {
return icon;
}
if (fontawesomeSvgCore.parse.icon) {
return fontawesomeSvgCore.parse.icon(icon);
}
if (icon === null) {
return null;
}
if (_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
};
}
}
var FontAwesomeIcon = vue.defineComponent({
name: 'FontAwesomeIcon',
props: {
border: {
type: Boolean,
default: false
},
fixedWidth: {
type: Boolean,
default: false
},
flip: {
type: [Boolean, String],
default: false,
validator: function validator(value) {
return [true, false, 'horizontal', 'vertical', 'both'].indexOf(value) > -1;
}
},
icon: {
type: [Object, Array, String],
required: true
},
mask: {
type: [Object, Array, String],
default: null
},
maskId: {
type: String,
default: null
},
listItem: {
type: Boolean,
default: false
},
pull: {
type: String,
default: null,
validator: function validator(value) {
return ['right', 'left'].indexOf(value) > -1;
}
},
pulse: {
type: Boolean,
default: false
},
rotation: {
type: [String, Number],
default: null,
validator: function validator(value) {
return [90, 180, 270].indexOf(Number.parseInt(value, 10)) > -1;
}
},
swapOpacity: {
type: Boolean,
default: false
},
size: {
type: String,
default: null,
validator: function validator(value) {
return ['2xs', 'xs', 'sm', 'lg', 'xl', '2xl', '1x', '2x', '3x', '4x', '5x', '6x', '7x', '8x', '9x', '10x'].indexOf(value) > -1;
}
},
spin: {
type: Boolean,
default: false
},
transform: {
type: [String, Object],
default: null
},
symbol: {
type: [Boolean, String],
default: false
},
title: {
type: String,
default: null
},
titleId: {
type: String,
default: null
},
inverse: {
type: Boolean,
default: false
},
bounce: {
type: Boolean,
default: false
},
shake: {
type: Boolean,
default: false
},
beat: {
type: Boolean,
default: false
},
fade: {
type: Boolean,
default: false
},
beatFade: {
type: Boolean,
default: false
},
flash: {
type: Boolean,
default: false
},
spinPulse: {
type: Boolean,
default: false
},
spinReverse: {
type: Boolean,
default: false
}
},
setup: function setup(props, _ref) {
var attrs = _ref.attrs;
var icon = vue.computed(function () {
return normalizeIconArgs(props.icon);
});
var classes = vue.computed(function () {
return objectWithKey('classes', classList(props));
});
var transform = vue.computed(function () {
return objectWithKey('transform', typeof props.transform === 'string' ? fontawesomeSvgCore.parse.transform(props.transform) : props.transform);
});
var mask = vue.computed(function () {
return objectWithKey('mask', normalizeIconArgs(props.mask));
});
var renderedIcon = vue.computed(function () {
return fontawesomeSvgCore.icon(icon.value, _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, classes.value), transform.value), mask.value), {}, {
symbol: props.symbol,
title: props.title,
titleId: props.titleId,
maskId: props.maskId
}));
});
vue.watch(renderedIcon, function (value) {
if (!value) {
return log('Could not find one or more icon(s)', icon.value, mask.value);
}
}, {
immediate: true
});
var vnode = vue.computed(function () {
return renderedIcon.value ? convert(renderedIcon.value.abstract[0], {}, attrs) : null;
});
return function () {
return vnode.value;
};
}
});
var FontAwesomeLayers = vue.defineComponent({
name: 'FontAwesomeLayers',
props: {
fixedWidth: {
type: Boolean,
default: false
}
},
setup: function setup(props, _ref) {
var slots = _ref.slots;
var familyPrefix = fontawesomeSvgCore.config.familyPrefix;
var className = vue.computed(function () {
return ["".concat(familyPrefix, "-layers")].concat(_toConsumableArray(props.fixedWidth ? ["".concat(familyPrefix, "-fw")] : []));
});
return function () {
return vue.h('div', {
class: className.value
}, slots.default ? slots.default() : []);
};
}
});
var FontAwesomeLayersText = vue.defineComponent({
name: 'FontAwesomeLayersText',
props: {
value: {
type: [String, Number],
default: ''
},
transform: {
type: [String, Object],
default: null
},
counter: {
type: Boolean,
default: false
},
position: {
type: String,
default: null,
validator: function validator(value) {
return ['bottom-left', 'bottom-right', 'top-left', 'top-right'].indexOf(value) > -1;
}
}
},
setup: function setup(props, _ref) {
var attrs = _ref.attrs;
var familyPrefix = fontawesomeSvgCore.config.familyPrefix;
var classes = vue.computed(function () {
return objectWithKey('classes', [].concat(_toConsumableArray(props.counter ? ["".concat(familyPrefix, "-layers-counter")] : []), _toConsumableArray(props.position ? ["".concat(familyPrefix, "-layers-").concat(props.position)] : [])));
});
var transform = vue.computed(function () {
return objectWithKey('transform', typeof props.transform === 'string' ? fontawesomeSvgCore.parse.transform(props.transform) : props.transform);
});
var abstractElement = vue.computed(function () {
var _text = fontawesomeSvgCore.text(props.value.toString(), _objectSpread2(_objectSpread2({}, transform.value), classes.value)),
abstract = _text.abstract;
if (props.counter) {
abstract[0].attributes.class = abstract[0].attributes.class.replace('fa-layers-text', '');
}
return abstract[0];
});
var vnode = vue.computed(function () {
return convert(abstractElement.value, {}, attrs);
});
return function () {
return vnode.value;
};
}
});
exports.FontAwesomeIcon = FontAwesomeIcon;
exports.FontAwesomeLayers = FontAwesomeLayers;
exports.FontAwesomeLayersText = FontAwesomeLayersText;
Object.defineProperty(exports, '__esModule', { value: true });
}));