@flexis/favicons
Version:
A tool for generating icons for the modern web.
1,092 lines (931 loc) • 36.9 kB
JavaScript
import _getIterator from '@babel/runtime-corejs3/core-js/get-iterator';
import _getIteratorMethod from '@babel/runtime-corejs3/core-js/get-iterator-method';
import _Symbol from '@babel/runtime-corejs3/core-js-stable/symbol';
import _Array$from from '@babel/runtime-corejs3/core-js-stable/array/from';
import _sliceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/slice';
import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
import _Promise from '@babel/runtime-corejs3/core-js-stable/promise';
import _Reflect$deleteProperty from '@babel/runtime-corejs3/core-js-stable/reflect/delete-property';
import _asyncToGenerator from '@babel/runtime-corejs3/helpers/asyncToGenerator';
import _toConsumableArray from '@babel/runtime-corejs3/helpers/toConsumableArray';
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
import _slicedToArray from '@babel/runtime-corejs3/helpers/slicedToArray';
import _Object$entries from '@babel/runtime-corejs3/core-js-stable/object/entries';
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
import _keysInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/keys';
import _regeneratorRuntime from '@babel/runtime-corejs3/regenerator';
import _Array$isArray from '@babel/runtime-corejs3/core-js-stable/array/is-array';
import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
import _Object$assign from '@babel/runtime-corejs3/core-js-stable/object/assign';
import _classCallCheck from '@babel/runtime-corejs3/helpers/classCallCheck';
import _createClass from '@babel/runtime-corejs3/helpers/createClass';
import _awaitAsyncGenerator from '@babel/runtime-corejs3/helpers/awaitAsyncGenerator';
import _wrapAsyncGenerator from '@babel/runtime-corejs3/helpers/wrapAsyncGenerator';
import _asyncIterator from '@babel/runtime-corejs3/helpers/asyncIterator';
import Vinyl from 'vinyl';
import toIco from 'to-ico';
import path, { join } from 'path';
import _sortInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/sort';
import _indexOfInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/index-of';
/**
* Add path to file name.
* @param path - Path to destination folder.
* @param filename - Target file name.
* @returns Full path to file.
*/
function applyPath(path, filename) {
return path ? join(path, filename) : filename;
}
/**
* Get complete icon config from shirt config.
* @param iconsType - Icons type name.
* @param iconsConfig - Icons shirt config.
* @param manifestConfig - Config to get background color.
* @returns Complete config.
*/
function getCompleteIconConfig(iconsType, iconsConfig, _ref) {
var background = _ref.background_color;
var iconConfigSource = iconsConfig[iconsType];
if (!iconConfigSource) {
return null;
}
var _ref2 = iconConfigSource === true ? {} : iconConfigSource,
iconOffsetSource = _ref2.offset,
iconBackgroundSource = _ref2.background;
var completeOffset = typeof iconOffsetSource !== 'undefined' ? iconOffsetSource : 0;
var completeBackground = typeof iconBackgroundSource !== 'undefined' ? iconBackgroundSource : false;
if (typeof completeBackground === 'boolean') {
if (iconsTransparency[iconsType] && !completeBackground) {
completeBackground = 'transparent';
} else {
completeBackground = background;
}
}
return {
offset: completeOffset,
background: completeBackground
};
}
var iconsTransparency = {
favicon: true,
android: true,
apple: false,
appleStartup: false
};
var iconsToGenerate = {
favicon: {
'favicon.ico': {
sizes: [{
width: 16,
height: 16
}, {
width: 24,
height: 24
}, {
width: 32,
height: 32
}, {
width: 48,
height: 48
}, {
width: 64,
height: 64
}]
},
'favicon-16x16.png': {
width: 16,
height: 16
},
'favicon-32x32.png': {
width: 32,
height: 32
}
},
android: {
'android-chrome-36x36.png': {
width: 36,
height: 36
},
'android-chrome-48x48.png': {
width: 48,
height: 48
},
'android-chrome-72x72.png': {
width: 72,
height: 72
},
'android-chrome-96x96.png': {
width: 96,
height: 96
},
'android-chrome-144x144.png': {
width: 144,
height: 144
},
'android-chrome-192x192.png': {
width: 192,
height: 192
},
'android-chrome-256x256.png': {
width: 256,
height: 256
},
'android-chrome-384x384.png': {
width: 384,
height: 384
},
'android-chrome-512x512.png': {
width: 512,
height: 512
}
},
// Sources of information:
// - https://stackoverflow.com/a/19933647
// - https://docs.axway.com/bundle/Titanium_SDK_allOS_en/page/icons_and_splash_screens.html
// - https://developer.apple.com/design/human-interface-guidelines/ios/icons-and-images/app-icon/
apple: {
// 'apple-touch-icon-57x57.png' - non-retina iPhone/iPod touch
// 'apple-touch-icon-60x60.png' - unknown or notification icon for native apps
// 'apple-touch-icon-72x72.png' - non-retina iPad
// 'apple-touch-icon-76x76.png' - also non-retina iPad
// 'apple-touch-icon-114x114.png' - retina iPhone with iOS < 7
// modern retina iPhone
'apple-touch-icon-120x120.png': {
width: 120,
height: 120
},
// 'apple-touch-icon-144x144.png' - retina iPad with iOS < 7
// modern retina iPad
'apple-touch-icon-152x152.png': {
width: 152,
height: 152
},
// iPad Pro
'apple-touch-icon-167x167.png': {
width: 167,
height: 167
},
// iPhone X, iPhone [N] Plus
'apple-touch-icon-180x180.png': {
width: 180,
height: 180
},
// generic?
'apple-touch-icon.png': {
width: 180,
height: 180
} // 'apple-touch-icon-precomposed.png' - iOS < 7
},
// Sources of information:
// - https://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions
// - https://docs.axway.com/bundle/Titanium_SDK_allOS_en/page/icons_and_splash_screens.html
// - https://developer.apple.com/design/human-interface-guidelines/ios/icons-and-images/launch-screen/
// - https://appsco.pe/developer/splash-screens
appleStartup: {
// iPhone 5
'apple-touch-startup-image-640x1136.png': {
width: 640,
height: 1136,
pixelRatio: 2
},
// iPhone
'apple-touch-startup-image-750x1334.png': {
width: 750,
height: 1334,
pixelRatio: 2
},
// iPhone [N] Plus
'apple-touch-startup-image-1242x2208.png': {
width: 1242,
height: 2208,
pixelRatio: 3,
rotate: false
},
'apple-touch-startup-image-2208x1242.png': {
width: 2208,
height: 1242,
pixelRatio: 3,
rotate: true
},
// iPhone X
'apple-touch-startup-image-1125x2436.png': {
width: 1125,
height: 2436,
pixelRatio: 3,
rotate: false
},
'apple-touch-startup-image-2436x1125.png': {
width: 2436,
height: 1125,
pixelRatio: 3,
rotate: true
},
// iPhone Xr
'apple-touch-startup-image-828x1792.png': {
width: 828,
height: 1792,
pixelRatio: 2,
rotate: false
},
'apple-touch-startup-image-1792x828.png': {
width: 1792,
height: 828,
pixelRatio: 2,
rotate: true
},
// iPhone Xs Max
'apple-touch-startup-image-1242x2688.png': {
width: 1242,
height: 2688,
pixelRatio: 3,
rotate: false
},
'apple-touch-startup-image-2688x1242.png': {
width: 2688,
height: 1242,
pixelRatio: 3,
rotate: true
},
// iPad Mini, Air
'apple-touch-startup-image-1536x2048.png': {
width: 1536,
height: 2048,
pixelRatio: 2,
rotate: false
},
'apple-touch-startup-image-2048x1536.png': {
width: 2048,
height: 1536,
pixelRatio: 2,
rotate: true
},
// iPad Pro 10.5"
'apple-touch-startup-image-1668x2224.png': {
width: 1668,
height: 2224,
pixelRatio: 2,
rotate: false
},
'apple-touch-startup-image-2224x1668.png': {
width: 2224,
height: 1668,
pixelRatio: 2,
rotate: true
},
// iPad Pro 11"
'apple-touch-startup-image-1668x2388.png': {
width: 1668,
height: 2388,
pixelRatio: 2,
rotate: false
},
'apple-touch-startup-image-2388x1668.png': {
width: 2224,
height: 2388,
pixelRatio: 2,
rotate: true
},
// iPad Pro 12.9"
'apple-touch-startup-image-2048x2732.png': {
width: 2048,
height: 2732,
pixelRatio: 2,
rotate: false
},
'apple-touch-startup-image-2732x2048.png': {
width: 2732,
height: 2048,
pixelRatio: 2,
rotate: true
}
}
};
var htmlHeaders = {
favicon: getFaviconHeaders,
android: getAndroidHeaders,
apple: getAppleHeaders,
appleStartup: getAppleStartupHeaders
};
/**
* Get "favicon" headers.
* @param headersConfig - Config params.
* @returns Array of headers objects.
*/
function getFaviconHeaders(_ref) {
var _context;
var path = _ref.path;
return _mapInstanceProperty(_context = _Object$entries(iconsToGenerate.favicon)).call(_context, function (_ref2) {
var _ref3 = _slicedToArray(_ref2, 2),
filename = _ref3[0],
_ref3$ = _ref3[1],
width = _ref3$.width,
height = _ref3$.height;
var header = {
tagName: 'link',
rel: 'icon',
href: applyPath(path, filename)
};
if (width && height) {
var _context2;
header.type = 'image/png';
header.sizes = _concatInstanceProperty(_context2 = "".concat(width, "x")).call(_context2, height);
}
return header;
});
}
/**
* Get "android" headers.
* @param headersConfig - Config params.
* @returns Array of headers objects.
*/
function getAndroidHeaders(_ref4) {
var path = _ref4.path,
_ref4$webAppCapable = _ref4.webAppCapable,
webAppCapable = _ref4$webAppCapable === void 0 ? 'yes' : _ref4$webAppCapable,
_ref4$manifest = _ref4.manifest;
_ref4$manifest = _ref4$manifest === void 0 ? {} : _ref4$manifest;
var _ref4$manifest$name = _ref4$manifest.name,
applicationName = _ref4$manifest$name === void 0 ? null : _ref4$manifest$name,
_ref4$manifest$theme_ = _ref4$manifest.theme_color,
themeColor = _ref4$manifest$theme_ === void 0 ? null : _ref4$manifest$theme_;
var headers = [{
tagName: 'link',
rel: 'manifest',
href: applyPath(path, 'manifest.json')
}, {
tagName: 'meta',
name: 'mobile-web-app-capable',
content: webAppCapable
}];
if (typeof applicationName === 'string') {
headers.push({
tagName: 'meta',
name: 'application-name',
content: applicationName
});
}
if (typeof themeColor === 'string') {
headers.push({
tagName: 'meta',
name: 'theme-color',
content: themeColor
});
}
return headers;
}
/**
* Get "apple" headers.
* @param headersConfig - Config params.
* @returns Array of headers objects.
*/
function getAppleHeaders(_ref5) {
var _context3;
var path = _ref5.path,
_ref5$webAppCapable = _ref5.webAppCapable,
webAppCapable = _ref5$webAppCapable === void 0 ? 'yes' : _ref5$webAppCapable,
_ref5$webAppStatusBar = _ref5.webAppStatusBarStyle,
webAppStatusBarStyle = _ref5$webAppStatusBar === void 0 ? 'black-translucent' : _ref5$webAppStatusBar,
_ref5$manifest = _ref5.manifest;
_ref5$manifest = _ref5$manifest === void 0 ? {} : _ref5$manifest;
var _ref5$manifest$name = _ref5$manifest.name,
applicationName = _ref5$manifest$name === void 0 ? null : _ref5$manifest$name;
var headers = [{
tagName: 'meta',
name: 'apple-mobile-web-app-capable',
content: webAppCapable
}, {
tagName: 'meta',
name: 'apple-mobile-web-app-status-bar-style',
content: webAppStatusBarStyle
}];
if (typeof applicationName === 'string') {
headers.push({
tagName: 'meta',
name: 'apple-mobile-web-app-title',
content: applicationName
});
}
var iconsHeaders = _mapInstanceProperty(_context3 = _Object$entries(iconsToGenerate.apple)).call(_context3, function (_ref6) {
var _context4;
var _ref7 = _slicedToArray(_ref6, 2),
filename = _ref7[0],
_ref7$ = _ref7[1],
width = _ref7$.width,
height = _ref7$.height;
return {
tagName: 'link',
rel: 'apple-touch-icon',
sizes: _concatInstanceProperty(_context4 = "".concat(width, "x")).call(_context4, height),
href: applyPath(path, filename)
};
});
headers.push.apply(headers, _toConsumableArray(iconsHeaders));
return headers;
}
/**
* Calculate media query for apple startup image.
* @param iconToGenerateConfig - Config with icon info.
* @returns Media query for device.
*/
function getAppleStartupMediaQuery(_ref8) {
var _context5;
var width = _ref8.width,
height = _ref8.height,
maybePixelRatio = _ref8.pixelRatio,
rotate = _ref8.rotate;
var pixelRatio = typeof maybePixelRatio === 'number' ? maybePixelRatio : 1;
var screenWidth = width / pixelRatio;
var screenHeight = height / pixelRatio;
var deviceWidth = rotate ? screenHeight : screenWidth;
var deviceHeight = rotate ? screenWidth : screenHeight;
var query = _concatInstanceProperty(_context5 = "(device-width: ".concat(deviceWidth, "px) and (device-height: ")).call(_context5, deviceHeight, "px)");
if (typeof rotate === 'boolean') {
query += " and (orientation: ".concat(rotate ? 'landscape' : 'portrait', ")");
}
if (pixelRatio > 1) {
query += " and (-webkit-device-pixel-ratio: ".concat(pixelRatio, ")");
}
return query;
}
/**
* Get "apple startup" headers.
* @param headersConfig - Config params.
* @returns Array of headers objects.
*/
function getAppleStartupHeaders(_ref9) {
var _context6;
var path = _ref9.path;
return _mapInstanceProperty(_context6 = _Object$entries(iconsToGenerate.appleStartup)).call(_context6, function (_ref10) {
var _ref11 = _slicedToArray(_ref10, 2),
filename = _ref11[0],
config = _ref11[1];
return {
tagName: 'link',
rel: 'apple-touch-startup-image',
media: getAppleStartupMediaQuery(config),
href: applyPath(path, filename)
};
});
}
var extensions = {
png: /^png$/,
svg: /^svg$/
};
/**
* Check image type
* @param type - Image extension without dot.
* @returns Image type is supported or not.
*/
function isSupportedType(type) {
return extensions.hasOwnProperty(type);
}
/**
* Check is "ico" or not.
* @param filename - File name to check.
* @returns Result of checking.
*/
function isIco(filename) {
return path.extname(filename) === '.ico';
}
/**
* Check is "svg" or not.
* @param filename - File name to check.
* @returns Result of checking.
*/
function isSvg(filename) {
return path.extname(filename) === '.svg';
}
var icons = {
favicon: true,
android: true,
apple: true,
appleStartup: true
};
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof _Symbol === "undefined" || _getIteratorMethod(o) == null) { if (_Array$isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = _getIterator(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { var _context15; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = _sliceInstanceProperty(_context15 = Object.prototype.toString.call(o)).call(_context15, 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 ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context13; _forEachInstanceProperty(_context13 = ownKeys(Object(source), true)).call(_context13, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context14; _forEachInstanceProperty(_context14 = ownKeys(Object(source))).call(_context14, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
var FaviconsGenerator = /*#__PURE__*/function () {
function FaviconsGenerator() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
path = _ref.path,
manifest = _ref.manifest,
icons$1 = _ref.icons;
_classCallCheck(this, FaviconsGenerator);
this.config = {};
_Object$assign(this.config, {
path: path,
manifest: _objectSpread({
background_color: '#fff'
}, manifest),
icons: icons$1 || icons
});
}
/**
* Create favicons form sources.
* @param sources - Favicons sources.
* @returns Results of handling.
*/
_createClass(FaviconsGenerator, [{
key: "generateIcons",
value: function generateIcons(source) {
var _this = this;
return _wrapAsyncGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
var sources, _iterator2, _step2, _source, sourceType, icons, iconsType, iconsOfType, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, icon;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
sources = _Array$isArray(source) ? source : [source];
if (sources.length) {
_context.next = 3;
break;
}
throw new Error('No sources provided.');
case 3:
_iterator2 = _createForOfIteratorHelper(sources);
_context.prev = 4;
_iterator2.s();
case 6:
if ((_step2 = _iterator2.n()).done) {
_context.next = 17;
break;
}
_source = _step2.value;
if (!(!Vinyl.isVinyl(_source) || _source.isNull() || _source.isStream())) {
_context.next = 10;
break;
}
throw new Error('Invalid source.');
case 10:
sourceType = _source.extname.replace(/^\./, '');
if (isSupportedType(sourceType)) {
_context.next = 13;
break;
}
throw new Error("\"".concat(sourceType, "\" is not supported."));
case 13:
_context.next = 15;
return _awaitAsyncGenerator(_this.attachMetadata(_source));
case 15:
_context.next = 6;
break;
case 17:
_context.next = 22;
break;
case 19:
_context.prev = 19;
_context.t0 = _context["catch"](4);
_iterator2.e(_context.t0);
case 22:
_context.prev = 22;
_iterator2.f();
return _context.finish(22);
case 25:
icons = _this.config.icons;
_context.t1 = _keysInstanceProperty(_regeneratorRuntime).call(_regeneratorRuntime, icons);
case 27:
if ((_context.t2 = _context.t1()).done) {
_context.next = 66;
break;
}
iconsType = _context.t2.value;
iconsOfType = _this.generateIconsOfType(iconsType, sources);
_iteratorNormalCompletion = true;
_didIteratorError = false;
_context.prev = 32;
_iterator = _asyncIterator(iconsOfType);
case 34:
_context.next = 36;
return _awaitAsyncGenerator(_iterator.next());
case 36:
_step = _context.sent;
_iteratorNormalCompletion = _step.done;
_context.next = 40;
return _awaitAsyncGenerator(_step.value);
case 40:
_value = _context.sent;
if (_iteratorNormalCompletion) {
_context.next = 48;
break;
}
icon = _value;
_context.next = 45;
return icon;
case 45:
_iteratorNormalCompletion = true;
_context.next = 34;
break;
case 48:
_context.next = 54;
break;
case 50:
_context.prev = 50;
_context.t3 = _context["catch"](32);
_didIteratorError = true;
_iteratorError = _context.t3;
case 54:
_context.prev = 54;
_context.prev = 55;
if (!(!_iteratorNormalCompletion && _iterator.return != null)) {
_context.next = 59;
break;
}
_context.next = 59;
return _awaitAsyncGenerator(_iterator.return());
case 59:
_context.prev = 59;
if (!_didIteratorError) {
_context.next = 62;
break;
}
throw _iteratorError;
case 62:
return _context.finish(59);
case 63:
return _context.finish(54);
case 64:
_context.next = 27;
break;
case 66:
case "end":
return _context.stop();
}
}
}, _callee, null, [[4, 19, 22, 25], [32, 50, 54, 64], [55,, 59, 63]]);
}))();
}
/**
* Create full manifest object with icons.
* @returns Manifest object.
*/
}, {
key: "generateManifset",
value: function generateManifset() {
var _this$config = this.config,
path = _this$config.path,
manifestConfig = _this$config.manifest,
android = _this$config.icons.android;
var manifest = _objectSpread({}, manifestConfig);
if (android) {
var _context2;
manifest.icons = _mapInstanceProperty(_context2 = _Object$entries(iconsToGenerate.android)).call(_context2, function (_ref2) {
var _context3;
var _ref3 = _slicedToArray(_ref2, 2),
filename = _ref3[0],
_ref3$ = _ref3[1],
width = _ref3$.width,
height = _ref3$.height;
return {
src: applyPath(path, filename),
sizes: _concatInstanceProperty(_context3 = "".concat(width, "x")).call(_context3, height),
type: 'image/png'
};
});
}
return manifest;
}
/**
* Create HTML-headers for target icons.
* @param headersConfig - Custom headers config.
* @returns Array of headers objects. You can get HTML-markup with `getHtmlHeadersMarkup` helper.
*/
}, {
key: "generateHtmlHeaders",
value: function generateHtmlHeaders() {
var _context4, _context5, _context6, _concatInstanceProper, _context7;
var headersConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _this$config$headersC = _objectSpread(_objectSpread(_objectSpread({}, this.config), headersConfig), {}, {
manifest: _objectSpread(_objectSpread({}, this.config.manifest), headersConfig.manifest)
}),
icons = _this$config$headersC.icons,
config = _objectWithoutProperties(_this$config$headersC, ["icons"]);
var headers = _mapInstanceProperty(_context4 = _filterInstanceProperty(_context5 = _Object$entries(icons)).call(_context5, function (_ref4) {
var _ref5 = _slicedToArray(_ref4, 2),
value = _ref5[1];
return value;
})).call(_context4, function (_ref6) {
var _ref7 = _slicedToArray(_ref6, 1),
type = _ref7[0];
return htmlHeaders[type](config);
});
return (_concatInstanceProper = _concatInstanceProperty(_context6 = [])).call.apply(_concatInstanceProper, _concatInstanceProperty(_context7 = [_context6]).call(_context7, _toConsumableArray(headers)));
}
/**
* Create icons of given type.
* @param iconsType - Type of needed icons.
* @param sources - Icons sources.
* @returns Icons of given type.
*/
}, {
key: "generateIconsOfType",
value: function generateIconsOfType(iconsType, sources) {
var _this2 = this;
return _wrapAsyncGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
var _this2$config, manifest, icons, iconConfig, iconsOfTypeToGenerate, filename;
return _regeneratorRuntime.wrap(function _callee2$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
_this2$config = _this2.config, manifest = _this2$config.manifest, icons = _this2$config.icons;
iconConfig = getCompleteIconConfig(iconsType, icons, manifest);
if (!(iconConfig === null)) {
_context8.next = 4;
break;
}
return _context8.abrupt("return");
case 4:
iconsOfTypeToGenerate = iconsToGenerate[iconsType];
_context8.t0 = _keysInstanceProperty(_regeneratorRuntime).call(_regeneratorRuntime, iconsOfTypeToGenerate);
case 6:
if ((_context8.t1 = _context8.t0()).done) {
_context8.next = 12;
break;
}
filename = _context8.t1.value;
_context8.next = 10;
return _this2.generateIcon(filename, sources, iconConfig, iconsOfTypeToGenerate[filename]);
case 10:
_context8.next = 6;
break;
case 12:
case "end":
return _context8.stop();
}
}
}, _callee2);
}))();
}
/**
* Create icon.
* @param filename - File name of icon.
* @param sources - Sources of icon.
* @param iconConfig - Icon config.
* @param iconToGenerateConfig - Icon to generate config.
*/
}, {
key: "generateIcon",
value: function () {
var _generateIcon = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(filename, sources, iconConfig, iconToGenerateConfig) {
var target, offset, background, width, height, icon;
return _regeneratorRuntime.wrap(function _callee3$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
if (!isIco(filename)) {
_context9.next = 2;
break;
}
return _context9.abrupt("return", this.generateIco(filename, sources, iconConfig, iconToGenerateConfig));
case 2:
target = sources[0].clone({
contents: false
});
offset = iconConfig.offset, background = iconConfig.background;
width = iconToGenerateConfig.width, height = iconToGenerateConfig.height;
_context9.next = 7;
return this.renderIcon(sources, {
width: width,
height: height,
background: background,
offset: offset
});
case 7:
icon = _context9.sent;
target.basename = filename;
target.contents = icon;
_Reflect$deleteProperty(target, 'metadata');
return _context9.abrupt("return", target);
case 12:
case "end":
return _context9.stop();
}
}
}, _callee3, this);
}));
function generateIcon(_x, _x2, _x3, _x4) {
return _generateIcon.apply(this, arguments);
}
return generateIcon;
}()
/**
* Create ".ico" icon.
* @param filename - File name of icon.
* @param sources - Sources of icon.
* @param iconConfig - Icon config.
* @param iconToGenerateConfig - Icon to generate config.
*/
}, {
key: "generateIco",
value: function () {
var _generateIco = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(filename, sources, iconConfig, iconToGenerateConfig) {
var _context10,
_this3 = this;
var target, icons, ico;
return _regeneratorRuntime.wrap(function _callee4$(_context12) {
while (1) {
switch (_context12.prev = _context12.next) {
case 0:
target = sources[0].clone({
contents: false
});
_context12.next = 3;
return _Promise.all(_mapInstanceProperty(_context10 = iconToGenerateConfig.sizes).call(_context10, function (_ref8) {
var _context11;
var width = _ref8.width,
height = _ref8.height;
return _this3.generateIcon(_concatInstanceProperty(_context11 = "".concat(width, "x")).call(_context11, height, ".png"), sources, iconConfig, _objectSpread(_objectSpread({}, iconToGenerateConfig), {}, {
width: width,
height: height
}));
}));
case 3:
icons = _context12.sent;
_context12.next = 6;
return toIco(_mapInstanceProperty(icons).call(icons, function (_ref9) {
var contents = _ref9.contents;
return contents;
}));
case 6:
ico = _context12.sent;
target.basename = filename;
target.contents = ico;
_Reflect$deleteProperty(target, 'metadata');
return _context12.abrupt("return", target);
case 11:
case "end":
return _context12.stop();
}
}
}, _callee4);
}));
function generateIco(_x5, _x6, _x7, _x8) {
return _generateIco.apply(this, arguments);
}
return generateIco;
}()
}]);
return FaviconsGenerator;
}();
var attributeNamesOrder = ['name', 'content', 'rel', 'type', 'sizes', 'media', 'href'];
/**
* Get order index of attribute name.
* @param attributeName - Target attribute name.
* @returns Index.
*/
function getAttributeOrder(attributeName) {
var index = _indexOfInstanceProperty(attributeNamesOrder).call(attributeNamesOrder, attributeName);
return index === -1 ? attributeNamesOrder.length : index;
}
/**
* Comparator function to sort attributes entries.
* @param a - Left attribute entry.
* @param b - Right attribute entry.
* @returns Result of comparation.
*/
function comparator(_ref, _ref2) {
var _ref3 = _slicedToArray(_ref, 1),
a = _ref3[0];
var _ref4 = _slicedToArray(_ref2, 1),
b = _ref4[0];
return getAttributeOrder(a) - getAttributeOrder(b);
}
/**
* Make attribute string from entry.
* @param entry - Entry with attribute name and value.
* @returns Attribute string.
*/
function entryToString(_ref5) {
var _context;
var _ref6 = _slicedToArray(_ref5, 2),
key = _ref6[0],
value = _ref6[1];
return _concatInstanceProperty(_context = "".concat(key, "=\"")).call(_context, String(value), "\"");
}
/**
* Get HTML-markup from objects.
* @param header - Object or array of objects with header info.
* @returns HTML-markup.
*/
function getHtmlHeadersMarkup(header) {
var _context2, _context3, _context4;
if (_Array$isArray(header)) {
return _mapInstanceProperty(header).call(header, getHtmlHeadersMarkup).join('\n');
}
var tagName = header.tagName,
attributes = _objectWithoutProperties(header, ["tagName"]);
var attributesString = _mapInstanceProperty(_context2 = _sortInstanceProperty(_context3 = _Object$entries(attributes)).call(_context3, comparator)).call(_context2, entryToString).join(' ');
var markup = _concatInstanceProperty(_context4 = "<".concat(tagName, " ")).call(_context4, attributesString, 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