main.js 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412
  1. /******/ (function(modules) { // webpackBootstrap
  2. /******/ // The module cache
  3. /******/ var installedModules = {};
  4. /******/
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/
  8. /******/ // Check if module is in cache
  9. /******/ if(installedModules[moduleId]) {
  10. /******/ return installedModules[moduleId].exports;
  11. /******/ }
  12. /******/ // Create a new module (and put it into the cache)
  13. /******/ var module = installedModules[moduleId] = {
  14. /******/ i: moduleId,
  15. /******/ l: false,
  16. /******/ exports: {}
  17. /******/ };
  18. /******/
  19. /******/ // Execute the module function
  20. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  21. /******/
  22. /******/ // Flag the module as loaded
  23. /******/ module.l = true;
  24. /******/
  25. /******/ // Return the exports of the module
  26. /******/ return module.exports;
  27. /******/ }
  28. /******/
  29. /******/
  30. /******/ // expose the modules object (__webpack_modules__)
  31. /******/ __webpack_require__.m = modules;
  32. /******/
  33. /******/ // expose the module cache
  34. /******/ __webpack_require__.c = installedModules;
  35. /******/
  36. /******/ // define getter function for harmony exports
  37. /******/ __webpack_require__.d = function(exports, name, getter) {
  38. /******/ if(!__webpack_require__.o(exports, name)) {
  39. /******/ Object.defineProperty(exports, name, {
  40. /******/ configurable: false,
  41. /******/ enumerable: true,
  42. /******/ get: getter
  43. /******/ });
  44. /******/ }
  45. /******/ };
  46. /******/
  47. /******/ // getDefaultExport function for compatibility with non-harmony modules
  48. /******/ __webpack_require__.n = function(module) {
  49. /******/ var getter = module && module.__esModule ?
  50. /******/ function getDefault() { return module['default']; } :
  51. /******/ function getModuleExports() { return module; };
  52. /******/ __webpack_require__.d(getter, 'a', getter);
  53. /******/ return getter;
  54. /******/ };
  55. /******/
  56. /******/ // Object.prototype.hasOwnProperty.call
  57. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  58. /******/
  59. /******/ // __webpack_public_path__
  60. /******/ __webpack_require__.p = "";
  61. /******/
  62. /******/ // Load entry module and return exports
  63. /******/ return __webpack_require__(__webpack_require__.s = 1);
  64. /******/ })
  65. /************************************************************************/
  66. /******/ ([
  67. /* 0 */
  68. /***/ (function(module, exports) {
  69. var g;
  70. // This works in non-strict mode
  71. g = (function() {
  72. return this;
  73. })();
  74. try {
  75. // This works if eval is allowed (see CSP)
  76. g = g || Function("return this")() || (1,eval)("this");
  77. } catch(e) {
  78. // This works if the window reference is available
  79. if(typeof window === "object")
  80. g = window;
  81. }
  82. // g can still be undefined, but nothing to do about it...
  83. // We return undefined, instead of nothing here, so it's
  84. // easier to handle this case. if(!global) { ...}
  85. module.exports = g;
  86. /***/ }),
  87. /* 1 */
  88. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  89. "use strict";
  90. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  91. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__assets_twitter_svg__ = __webpack_require__(2);
  92. /***/ }),
  93. /* 2 */
  94. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  95. "use strict";
  96. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__node_modules_svg_baker_runtime_browser_symbol_js__ = __webpack_require__(3);
  97. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__node_modules_svg_baker_runtime_browser_symbol_js___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__node_modules_svg_baker_runtime_browser_symbol_js__);
  98. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__runtime_browser_sprite_build_js__ = __webpack_require__(4);
  99. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__runtime_browser_sprite_build_js___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1__runtime_browser_sprite_build_js__);
  100. var symbol = new __WEBPACK_IMPORTED_MODULE_0__node_modules_svg_baker_runtime_browser_symbol_js___default.a({
  101. "id": "twitter",
  102. "use": "twitter-usage",
  103. "viewBox": "0 0 273.4 222.2",
  104. "content": "<symbol xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 273.4 222.2\" id=\"twitter\"><path d=\"M273.4 26.3c-10.1 4.5-20.9 7.5-32.2 8.8 11.6-6.9 20.5-17.9 24.7-31-10.9 6.4-22.9 11.1-35.7 13.6A55.919 55.919 0 0 0 189.3 0c-31 0-56.1 25.1-56.1 56.1 0 4.4.5 8.7 1.5 12.8C88 66.5 46.7 44.2 19 10.3c-4.8 8.3-7.6 17.9-7.6 28.2 0 19.5 9.9 36.6 25 46.7-9.2-.3-17.8-2.8-25.4-7v.7c0 27.2 19.3 49.8 45 55-4.7 1.3-9.7 2-14.8 2-3.6 0-7.1-.4-10.6-1 7.1 22.3 27.9 38.5 52.4 39-19.2 15-43.4 24-69.7 24-4.5 0-9-.3-13.4-.8 24.8 15.9 54.3 25.2 86 25.2 103.2 0 159.6-85.5 159.6-159.6 0-2.4-.1-4.9-.2-7.3 11.1-8 20.6-17.9 28.1-29.1z\" /></symbol>"
  105. });
  106. var result = __WEBPACK_IMPORTED_MODULE_1__runtime_browser_sprite_build_js___default.a.add(symbol);
  107. /* unused harmony default export */ var _unused_webpack_default_export = (symbol);
  108. /***/ }),
  109. /* 3 */
  110. /***/ (function(module, exports, __webpack_require__) {
  111. /* WEBPACK VAR INJECTION */(function(global) {(function (global, factory) {
  112. true ? module.exports = factory() :
  113. typeof define === 'function' && define.amd ? define(factory) :
  114. (global.BrowserSpriteSymbol = factory());
  115. }(this, (function () { 'use strict';
  116. var SpriteSymbol = function SpriteSymbol(ref) {
  117. var id = ref.id;
  118. var viewBox = ref.viewBox;
  119. var content = ref.content;
  120. this.id = id;
  121. this.viewBox = viewBox;
  122. this.content = content;
  123. };
  124. /**
  125. * @return {string}
  126. */
  127. SpriteSymbol.prototype.stringify = function stringify () {
  128. return this.content;
  129. };
  130. /**
  131. * @return {string}
  132. */
  133. SpriteSymbol.prototype.toString = function toString () {
  134. return this.stringify();
  135. };
  136. SpriteSymbol.prototype.destroy = function destroy () {
  137. var this$1 = this;
  138. ['id', 'viewBox', 'content'].forEach(function (prop) { return delete this$1[prop]; });
  139. };
  140. /**
  141. * @param {string} content
  142. * @return {Element}
  143. */
  144. var parse = function (content) {
  145. var hasImportNode = !!document.importNode;
  146. var doc = new DOMParser().parseFromString(content, 'image/svg+xml').documentElement;
  147. /**
  148. * Fix for browser which are throwing WrongDocumentError
  149. * if you insert an element which is not part of the document
  150. * @see http://stackoverflow.com/a/7986519/4624403
  151. */
  152. if (hasImportNode) {
  153. return document.importNode(doc, true);
  154. }
  155. return doc;
  156. };
  157. var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  158. function createCommonjsModule(fn, module) {
  159. return module = { exports: {} }, fn(module, module.exports), module.exports;
  160. }
  161. var deepmerge = createCommonjsModule(function (module, exports) {
  162. (function (root, factory) {
  163. if (false) {
  164. undefined(factory);
  165. } else {
  166. module.exports = factory();
  167. }
  168. }(commonjsGlobal, function () {
  169. function isMergeableObject(val) {
  170. var nonNullObject = val && typeof val === 'object';
  171. return nonNullObject
  172. && Object.prototype.toString.call(val) !== '[object RegExp]'
  173. && Object.prototype.toString.call(val) !== '[object Date]'
  174. }
  175. function emptyTarget(val) {
  176. return Array.isArray(val) ? [] : {}
  177. }
  178. function cloneIfNecessary(value, optionsArgument) {
  179. var clone = optionsArgument && optionsArgument.clone === true;
  180. return (clone && isMergeableObject(value)) ? deepmerge(emptyTarget(value), value, optionsArgument) : value
  181. }
  182. function defaultArrayMerge(target, source, optionsArgument) {
  183. var destination = target.slice();
  184. source.forEach(function(e, i) {
  185. if (typeof destination[i] === 'undefined') {
  186. destination[i] = cloneIfNecessary(e, optionsArgument);
  187. } else if (isMergeableObject(e)) {
  188. destination[i] = deepmerge(target[i], e, optionsArgument);
  189. } else if (target.indexOf(e) === -1) {
  190. destination.push(cloneIfNecessary(e, optionsArgument));
  191. }
  192. });
  193. return destination
  194. }
  195. function mergeObject(target, source, optionsArgument) {
  196. var destination = {};
  197. if (isMergeableObject(target)) {
  198. Object.keys(target).forEach(function (key) {
  199. destination[key] = cloneIfNecessary(target[key], optionsArgument);
  200. });
  201. }
  202. Object.keys(source).forEach(function (key) {
  203. if (!isMergeableObject(source[key]) || !target[key]) {
  204. destination[key] = cloneIfNecessary(source[key], optionsArgument);
  205. } else {
  206. destination[key] = deepmerge(target[key], source[key], optionsArgument);
  207. }
  208. });
  209. return destination
  210. }
  211. function deepmerge(target, source, optionsArgument) {
  212. var array = Array.isArray(source);
  213. var options = optionsArgument || { arrayMerge: defaultArrayMerge };
  214. var arrayMerge = options.arrayMerge || defaultArrayMerge;
  215. if (array) {
  216. return Array.isArray(target) ? arrayMerge(target, source, optionsArgument) : cloneIfNecessary(source, optionsArgument)
  217. } else {
  218. return mergeObject(target, source, optionsArgument)
  219. }
  220. }
  221. deepmerge.all = function deepmergeAll(array, optionsArgument) {
  222. if (!Array.isArray(array) || array.length < 2) {
  223. throw new Error('first argument should be an array with at least two elements')
  224. }
  225. // we are sure there are at least 2 values, so it is safe to have no initial value
  226. return array.reduce(function(prev, next) {
  227. return deepmerge(prev, next, optionsArgument)
  228. })
  229. };
  230. return deepmerge
  231. }));
  232. });
  233. var namespaces_1 = createCommonjsModule(function (module, exports) {
  234. var namespaces = {
  235. svg: {
  236. name: 'xmlns',
  237. uri: 'http://www.w3.org/2000/svg'
  238. },
  239. xlink: {
  240. name: 'xmlns:xlink',
  241. uri: 'http://www.w3.org/1999/xlink'
  242. }
  243. };
  244. exports.default = namespaces;
  245. module.exports = exports.default;
  246. });
  247. /**
  248. * @param {Object} attrs
  249. * @return {string}
  250. */
  251. var objectToAttrsString = function (attrs) {
  252. return Object.keys(attrs).map(function (attr) {
  253. var value = attrs[attr].toString().replace(/"/g, '&quot;');
  254. return (attr + "=\"" + value + "\"");
  255. }).join(' ');
  256. };
  257. var svg = namespaces_1.svg;
  258. var xlink = namespaces_1.xlink;
  259. var defaultAttrs = {};
  260. defaultAttrs[svg.name] = svg.uri;
  261. defaultAttrs[xlink.name] = xlink.uri;
  262. /**
  263. * @param {string} [content]
  264. * @param {Object} [attributes]
  265. * @return {string}
  266. */
  267. var wrapInSvgString = function (content, attributes) {
  268. if ( content === void 0 ) content = '';
  269. var attrs = deepmerge(defaultAttrs, attributes || {});
  270. var attrsRendered = objectToAttrsString(attrs);
  271. return ("<svg " + attrsRendered + ">" + content + "</svg>");
  272. };
  273. var BrowserSpriteSymbol = (function (SpriteSymbol$$1) {
  274. function BrowserSpriteSymbol () {
  275. SpriteSymbol$$1.apply(this, arguments);
  276. }
  277. if ( SpriteSymbol$$1 ) BrowserSpriteSymbol.__proto__ = SpriteSymbol$$1;
  278. BrowserSpriteSymbol.prototype = Object.create( SpriteSymbol$$1 && SpriteSymbol$$1.prototype );
  279. BrowserSpriteSymbol.prototype.constructor = BrowserSpriteSymbol;
  280. var prototypeAccessors = { isMounted: {} };
  281. prototypeAccessors.isMounted.get = function () {
  282. return !!this.node;
  283. };
  284. /**
  285. * @param {Element} node
  286. * @return {BrowserSpriteSymbol}
  287. */
  288. BrowserSpriteSymbol.createFromExistingNode = function createFromExistingNode (node) {
  289. return new BrowserSpriteSymbol({
  290. id: node.getAttribute('id'),
  291. viewBox: node.getAttribute('viewBox'),
  292. content: node.outerHTML
  293. });
  294. };
  295. BrowserSpriteSymbol.prototype.destroy = function destroy () {
  296. if (this.isMounted) {
  297. this.unmount();
  298. }
  299. SpriteSymbol$$1.prototype.destroy.call(this);
  300. };
  301. /**
  302. * @param {Element|string} target
  303. * @return {Element}
  304. */
  305. BrowserSpriteSymbol.prototype.mount = function mount (target) {
  306. if (this.isMounted) {
  307. return this.node;
  308. }
  309. var mountTarget = typeof target === 'string' ? document.querySelector(target) : target;
  310. var node = this.render();
  311. this.node = node;
  312. mountTarget.appendChild(node);
  313. return node;
  314. };
  315. /**
  316. * @return {Element}
  317. */
  318. BrowserSpriteSymbol.prototype.render = function render () {
  319. var content = this.stringify();
  320. return parse(wrapInSvgString(content)).childNodes[0];
  321. };
  322. BrowserSpriteSymbol.prototype.unmount = function unmount () {
  323. this.node.parentNode.removeChild(this.node);
  324. };
  325. Object.defineProperties( BrowserSpriteSymbol.prototype, prototypeAccessors );
  326. return BrowserSpriteSymbol;
  327. }(SpriteSymbol));
  328. return BrowserSpriteSymbol;
  329. })));
  330. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
  331. /***/ }),
  332. /* 4 */
  333. /***/ (function(module, exports, __webpack_require__) {
  334. /* WEBPACK VAR INJECTION */(function(global) {(function (global, factory) {
  335. true ? module.exports = factory() :
  336. typeof define === 'function' && define.amd ? define(factory) :
  337. (global.BrowserSprite = factory());
  338. }(this, (function () { 'use strict';
  339. var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  340. function createCommonjsModule(fn, module) {
  341. return module = { exports: {} }, fn(module, module.exports), module.exports;
  342. }
  343. var deepmerge = createCommonjsModule(function (module, exports) {
  344. (function (root, factory) {
  345. if (false) {
  346. undefined(factory);
  347. } else {
  348. module.exports = factory();
  349. }
  350. }(commonjsGlobal, function () {
  351. function isMergeableObject(val) {
  352. var nonNullObject = val && typeof val === 'object';
  353. return nonNullObject
  354. && Object.prototype.toString.call(val) !== '[object RegExp]'
  355. && Object.prototype.toString.call(val) !== '[object Date]'
  356. }
  357. function emptyTarget(val) {
  358. return Array.isArray(val) ? [] : {}
  359. }
  360. function cloneIfNecessary(value, optionsArgument) {
  361. var clone = optionsArgument && optionsArgument.clone === true;
  362. return (clone && isMergeableObject(value)) ? deepmerge(emptyTarget(value), value, optionsArgument) : value
  363. }
  364. function defaultArrayMerge(target, source, optionsArgument) {
  365. var destination = target.slice();
  366. source.forEach(function(e, i) {
  367. if (typeof destination[i] === 'undefined') {
  368. destination[i] = cloneIfNecessary(e, optionsArgument);
  369. } else if (isMergeableObject(e)) {
  370. destination[i] = deepmerge(target[i], e, optionsArgument);
  371. } else if (target.indexOf(e) === -1) {
  372. destination.push(cloneIfNecessary(e, optionsArgument));
  373. }
  374. });
  375. return destination
  376. }
  377. function mergeObject(target, source, optionsArgument) {
  378. var destination = {};
  379. if (isMergeableObject(target)) {
  380. Object.keys(target).forEach(function (key) {
  381. destination[key] = cloneIfNecessary(target[key], optionsArgument);
  382. });
  383. }
  384. Object.keys(source).forEach(function (key) {
  385. if (!isMergeableObject(source[key]) || !target[key]) {
  386. destination[key] = cloneIfNecessary(source[key], optionsArgument);
  387. } else {
  388. destination[key] = deepmerge(target[key], source[key], optionsArgument);
  389. }
  390. });
  391. return destination
  392. }
  393. function deepmerge(target, source, optionsArgument) {
  394. var array = Array.isArray(source);
  395. var options = optionsArgument || { arrayMerge: defaultArrayMerge };
  396. var arrayMerge = options.arrayMerge || defaultArrayMerge;
  397. if (array) {
  398. return Array.isArray(target) ? arrayMerge(target, source, optionsArgument) : cloneIfNecessary(source, optionsArgument)
  399. } else {
  400. return mergeObject(target, source, optionsArgument)
  401. }
  402. }
  403. deepmerge.all = function deepmergeAll(array, optionsArgument) {
  404. if (!Array.isArray(array) || array.length < 2) {
  405. throw new Error('first argument should be an array with at least two elements')
  406. }
  407. // we are sure there are at least 2 values, so it is safe to have no initial value
  408. return array.reduce(function(prev, next) {
  409. return deepmerge(prev, next, optionsArgument)
  410. })
  411. };
  412. return deepmerge
  413. }));
  414. });
  415. //
  416. // An event handler can take an optional event argument
  417. // and should not return a value
  418. // An array of all currently registered event handlers for a type
  419. // A map of event types and their corresponding event handlers.
  420. /** Mitt: Tiny (~200b) functional event emitter / pubsub.
  421. * @name mitt
  422. * @returns {Mitt}
  423. */
  424. function mitt(all ) {
  425. all = all || Object.create(null);
  426. return {
  427. /**
  428. * Register an event handler for the given type.
  429. *
  430. * @param {String} type Type of event to listen for, or `"*"` for all events
  431. * @param {Function} handler Function to call in response to given event
  432. * @memberOf mitt
  433. */
  434. on: function on(type , handler ) {
  435. (all[type] || (all[type] = [])).push(handler);
  436. },
  437. /**
  438. * Remove an event handler for the given type.
  439. *
  440. * @param {String} type Type of event to unregister `handler` from, or `"*"`
  441. * @param {Function} handler Handler function to remove
  442. * @memberOf mitt
  443. */
  444. off: function off(type , handler ) {
  445. if (all[type]) {
  446. all[type].splice(all[type].indexOf(handler) >>> 0, 1);
  447. }
  448. },
  449. /**
  450. * Invoke all handlers for the given type.
  451. * If present, `"*"` handlers are invoked after type-matched handlers.
  452. *
  453. * @param {String} type The event type to invoke
  454. * @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler
  455. * @memberof mitt
  456. */
  457. emit: function emit(type , evt ) {
  458. (all[type] || []).map(function (handler) { handler(evt); });
  459. (all['*'] || []).map(function (handler) { handler(type, evt); });
  460. }
  461. };
  462. }
  463. var namespaces_1 = createCommonjsModule(function (module, exports) {
  464. var namespaces = {
  465. svg: {
  466. name: 'xmlns',
  467. uri: 'http://www.w3.org/2000/svg'
  468. },
  469. xlink: {
  470. name: 'xmlns:xlink',
  471. uri: 'http://www.w3.org/1999/xlink'
  472. }
  473. };
  474. exports.default = namespaces;
  475. module.exports = exports.default;
  476. });
  477. /**
  478. * @param {Object} attrs
  479. * @return {string}
  480. */
  481. var objectToAttrsString = function (attrs) {
  482. return Object.keys(attrs).map(function (attr) {
  483. var value = attrs[attr].toString().replace(/"/g, '&quot;');
  484. return (attr + "=\"" + value + "\"");
  485. }).join(' ');
  486. };
  487. var svg = namespaces_1.svg;
  488. var xlink = namespaces_1.xlink;
  489. var defaultAttrs = {};
  490. defaultAttrs[svg.name] = svg.uri;
  491. defaultAttrs[xlink.name] = xlink.uri;
  492. /**
  493. * @param {string} [content]
  494. * @param {Object} [attributes]
  495. * @return {string}
  496. */
  497. var wrapInSvgString = function (content, attributes) {
  498. if ( content === void 0 ) content = '';
  499. var attrs = deepmerge(defaultAttrs, attributes || {});
  500. var attrsRendered = objectToAttrsString(attrs);
  501. return ("<svg " + attrsRendered + ">" + content + "</svg>");
  502. };
  503. var svg$1 = namespaces_1.svg;
  504. var xlink$1 = namespaces_1.xlink;
  505. var defaultConfig = {
  506. attrs: ( obj = {
  507. style: ['position: absolute', 'width: 0', 'height: 0'].join('; ')
  508. }, obj[svg$1.name] = svg$1.uri, obj[xlink$1.name] = xlink$1.uri, obj )
  509. };
  510. var obj;
  511. var Sprite = function Sprite(config) {
  512. this.config = deepmerge(defaultConfig, config || {});
  513. this.symbols = [];
  514. };
  515. /**
  516. * Add new symbol. If symbol with the same id exists it will be replaced.
  517. * @param {SpriteSymbol} symbol
  518. * @return {boolean} `true` - symbol was added, `false` - replaced
  519. */
  520. Sprite.prototype.add = function add (symbol) {
  521. var ref = this;
  522. var symbols = ref.symbols;
  523. var existing = this.find(symbol.id);
  524. if (existing) {
  525. symbols[symbols.indexOf(existing)] = symbol;
  526. return false;
  527. }
  528. symbols.push(symbol);
  529. return true;
  530. };
  531. /**
  532. * Remove symbol & destroy it
  533. * @param {string} id
  534. * @return {boolean} `true` - symbol was found & successfully destroyed, `false` - otherwise
  535. */
  536. Sprite.prototype.remove = function remove (id) {
  537. var ref = this;
  538. var symbols = ref.symbols;
  539. var symbol = this.find(id);
  540. if (symbol) {
  541. symbols.splice(symbols.indexOf(symbol), 1);
  542. symbol.destroy();
  543. return true;
  544. }
  545. return false;
  546. };
  547. /**
  548. * @param {string} id
  549. * @return {SpriteSymbol|null}
  550. */
  551. Sprite.prototype.find = function find (id) {
  552. return this.symbols.filter(function (s) { return s.id === id; })[0] || null;
  553. };
  554. /**
  555. * @param {string} id
  556. * @return {boolean}
  557. */
  558. Sprite.prototype.has = function has (id) {
  559. return this.find(id) !== null;
  560. };
  561. /**
  562. * @return {string}
  563. */
  564. Sprite.prototype.stringify = function stringify () {
  565. var ref = this.config;
  566. var attrs = ref.attrs;
  567. var stringifiedSymbols = this.symbols.map(function (s) { return s.stringify(); }).join('');
  568. return wrapInSvgString(stringifiedSymbols, attrs);
  569. };
  570. /**
  571. * @return {string}
  572. */
  573. Sprite.prototype.toString = function toString () {
  574. return this.stringify();
  575. };
  576. Sprite.prototype.destroy = function destroy () {
  577. this.symbols.forEach(function (s) { return s.destroy(); });
  578. };
  579. var SpriteSymbol = function SpriteSymbol(ref) {
  580. var id = ref.id;
  581. var viewBox = ref.viewBox;
  582. var content = ref.content;
  583. this.id = id;
  584. this.viewBox = viewBox;
  585. this.content = content;
  586. };
  587. /**
  588. * @return {string}
  589. */
  590. SpriteSymbol.prototype.stringify = function stringify () {
  591. return this.content;
  592. };
  593. /**
  594. * @return {string}
  595. */
  596. SpriteSymbol.prototype.toString = function toString () {
  597. return this.stringify();
  598. };
  599. SpriteSymbol.prototype.destroy = function destroy () {
  600. var this$1 = this;
  601. ['id', 'viewBox', 'content'].forEach(function (prop) { return delete this$1[prop]; });
  602. };
  603. /**
  604. * @param {string} content
  605. * @return {Element}
  606. */
  607. var parse = function (content) {
  608. var hasImportNode = !!document.importNode;
  609. var doc = new DOMParser().parseFromString(content, 'image/svg+xml').documentElement;
  610. /**
  611. * Fix for browser which are throwing WrongDocumentError
  612. * if you insert an element which is not part of the document
  613. * @see http://stackoverflow.com/a/7986519/4624403
  614. */
  615. if (hasImportNode) {
  616. return document.importNode(doc, true);
  617. }
  618. return doc;
  619. };
  620. var BrowserSpriteSymbol = (function (SpriteSymbol$$1) {
  621. function BrowserSpriteSymbol () {
  622. SpriteSymbol$$1.apply(this, arguments);
  623. }
  624. if ( SpriteSymbol$$1 ) BrowserSpriteSymbol.__proto__ = SpriteSymbol$$1;
  625. BrowserSpriteSymbol.prototype = Object.create( SpriteSymbol$$1 && SpriteSymbol$$1.prototype );
  626. BrowserSpriteSymbol.prototype.constructor = BrowserSpriteSymbol;
  627. var prototypeAccessors = { isMounted: {} };
  628. prototypeAccessors.isMounted.get = function () {
  629. return !!this.node;
  630. };
  631. /**
  632. * @param {Element} node
  633. * @return {BrowserSpriteSymbol}
  634. */
  635. BrowserSpriteSymbol.createFromExistingNode = function createFromExistingNode (node) {
  636. return new BrowserSpriteSymbol({
  637. id: node.getAttribute('id'),
  638. viewBox: node.getAttribute('viewBox'),
  639. content: node.outerHTML
  640. });
  641. };
  642. BrowserSpriteSymbol.prototype.destroy = function destroy () {
  643. if (this.isMounted) {
  644. this.unmount();
  645. }
  646. SpriteSymbol$$1.prototype.destroy.call(this);
  647. };
  648. /**
  649. * @param {Element|string} target
  650. * @return {Element}
  651. */
  652. BrowserSpriteSymbol.prototype.mount = function mount (target) {
  653. if (this.isMounted) {
  654. return this.node;
  655. }
  656. var mountTarget = typeof target === 'string' ? document.querySelector(target) : target;
  657. var node = this.render();
  658. this.node = node;
  659. mountTarget.appendChild(node);
  660. return node;
  661. };
  662. /**
  663. * @return {Element}
  664. */
  665. BrowserSpriteSymbol.prototype.render = function render () {
  666. var content = this.stringify();
  667. return parse(wrapInSvgString(content)).childNodes[0];
  668. };
  669. BrowserSpriteSymbol.prototype.unmount = function unmount () {
  670. this.node.parentNode.removeChild(this.node);
  671. };
  672. Object.defineProperties( BrowserSpriteSymbol.prototype, prototypeAccessors );
  673. return BrowserSpriteSymbol;
  674. }(SpriteSymbol));
  675. var defaultConfig$1 = {
  676. /**
  677. * Should following options be automatically configured:
  678. * - `syncUrlsWithBaseTag`
  679. * - `locationChangeAngularEmitter`
  680. * - `moveGradientsOutsideSymbol`
  681. * @type {boolean}
  682. */
  683. autoConfigure: true,
  684. /**
  685. * Default mounting selector
  686. * @type {string}
  687. */
  688. mountTo: 'body',
  689. /**
  690. * Fix disappearing SVG elements when <base href> exists.
  691. * Executes when sprite mounted.
  692. * @see http://stackoverflow.com/a/18265336/796152
  693. * @see https://github.com/everdimension/angular-svg-base-fix
  694. * @see https://github.com/angular/angular.js/issues/8934#issuecomment-56568466
  695. * @type {boolean}
  696. */
  697. syncUrlsWithBaseTag: false,
  698. /**
  699. * Should sprite listen custom location change event
  700. * @type {boolean}
  701. */
  702. listenLocationChangeEvent: true,
  703. /**
  704. * Custom window event name which should be emitted to update sprite urls
  705. * @type {string}
  706. */
  707. locationChangeEvent: 'locationChange',
  708. /**
  709. * Emit location change event in Angular automatically
  710. * @type {boolean}
  711. */
  712. locationChangeAngularEmitter: false,
  713. /**
  714. * Selector to find symbols usages when updating sprite urls
  715. * @type {string}
  716. */
  717. usagesToUpdate: 'use[*|href]',
  718. /**
  719. * Fix Firefox bug when gradients and patterns don't work if they are within a symbol.
  720. * Executes when sprite is rendered, but not mounted.
  721. * @see https://bugzilla.mozilla.org/show_bug.cgi?id=306674
  722. * @see https://bugzilla.mozilla.org/show_bug.cgi?id=353575
  723. * @see https://bugzilla.mozilla.org/show_bug.cgi?id=1235364
  724. * @type {boolean}
  725. */
  726. moveGradientsOutsideSymbol: false
  727. };
  728. /**
  729. * @param {*} arrayLike
  730. * @return {Array}
  731. */
  732. var arrayFrom = function (arrayLike) {
  733. return Array.prototype.slice.call(arrayLike, 0);
  734. };
  735. var browser = {
  736. isChrome: function () { return /chrome/i.test(navigator.userAgent); },
  737. isFirefox: function () { return /firefox/i.test(navigator.userAgent); },
  738. // https://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx
  739. isIE: function () { return /msie/i.test(navigator.userAgent) || /trident/i.test(navigator.userAgent); },
  740. isEdge: function () { return /edge/i.test(navigator.userAgent); }
  741. };
  742. /**
  743. * @param {string} name
  744. * @param {*} data
  745. */
  746. var dispatchEvent = function (name, data) {
  747. var event = document.createEvent('CustomEvent');
  748. event.initCustomEvent(name, false, false, data);
  749. window.dispatchEvent(event);
  750. };
  751. /**
  752. * IE doesn't evaluate <style> tags in SVGs that are dynamically added to the page.
  753. * This trick will trigger IE to read and use any existing SVG <style> tags.
  754. * @see https://github.com/iconic/SVGInjector/issues/23
  755. * @see https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10898469/
  756. *
  757. * @param {Element} node DOM Element to search <style> tags in
  758. * @return {Array<HTMLStyleElement>}
  759. */
  760. var evalStylesIEWorkaround = function (node) {
  761. var updatedNodes = [];
  762. arrayFrom(node.querySelectorAll('style'))
  763. .forEach(function (style) {
  764. style.textContent += '';
  765. updatedNodes.push(style);
  766. });
  767. return updatedNodes;
  768. };
  769. /**
  770. * @param {string} [url] If not provided - current URL will be used
  771. * @return {string}
  772. */
  773. var getUrlWithoutFragment = function (url) {
  774. return (url || window.location.href).split('#')[0];
  775. };
  776. /* global angular */
  777. /**
  778. * @param {string} eventName
  779. */
  780. var locationChangeAngularEmitter = function (eventName) {
  781. angular.module('ng').run(['$rootScope', function ($rootScope) {
  782. $rootScope.$on('$locationChangeSuccess', function (e, newUrl, oldUrl) {
  783. dispatchEvent(eventName, { oldUrl: oldUrl, newUrl: newUrl });
  784. });
  785. }]);
  786. };
  787. var defaultSelector = 'linearGradient, radialGradient, pattern';
  788. /**
  789. * @param {Element} svg
  790. * @param {string} [selector]
  791. * @return {Element}
  792. */
  793. var moveGradientsOutsideSymbol = function (svg, selector) {
  794. if ( selector === void 0 ) selector = defaultSelector;
  795. arrayFrom(svg.querySelectorAll('symbol')).forEach(function (symbol) {
  796. arrayFrom(symbol.querySelectorAll(selector)).forEach(function (node) {
  797. symbol.parentNode.insertBefore(node, symbol);
  798. });
  799. });
  800. return svg;
  801. };
  802. /**
  803. * @param {NodeList} nodes
  804. * @param {Function} [matcher]
  805. * @return {Attr[]}
  806. */
  807. function selectAttributes(nodes, matcher) {
  808. var attrs = arrayFrom(nodes).reduce(function (acc, node) {
  809. if (!node.attributes) {
  810. return acc;
  811. }
  812. var arrayfied = arrayFrom(node.attributes);
  813. var matched = matcher ? arrayfied.filter(matcher) : arrayfied;
  814. return acc.concat(matched);
  815. }, []);
  816. return attrs;
  817. }
  818. /**
  819. * @param {NodeList|Node} nodes
  820. * @param {boolean} [clone=true]
  821. * @return {string}
  822. */
  823. var xLinkNS = namespaces_1.xlink.uri;
  824. var xLinkAttrName = 'xlink:href';
  825. // eslint-disable-next-line no-useless-escape
  826. var specialUrlCharsPattern = /[{}|\\\^\[\]`"<>]/g;
  827. function encoder(url) {
  828. return url.replace(specialUrlCharsPattern, function (match) {
  829. return ("%" + (match[0].charCodeAt(0).toString(16).toUpperCase()));
  830. });
  831. }
  832. function escapeRegExp(str) {
  833. return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
  834. }
  835. /**
  836. * @param {NodeList} nodes
  837. * @param {string} startsWith
  838. * @param {string} replaceWith
  839. * @return {NodeList}
  840. */
  841. function updateReferences(nodes, startsWith, replaceWith) {
  842. arrayFrom(nodes).forEach(function (node) {
  843. var href = node.getAttribute(xLinkAttrName);
  844. if (href && href.indexOf(startsWith) === 0) {
  845. var newUrl = href.replace(startsWith, replaceWith);
  846. node.setAttributeNS(xLinkNS, xLinkAttrName, newUrl);
  847. }
  848. });
  849. return nodes;
  850. }
  851. /**
  852. * List of SVG attributes to update url() target in them
  853. */
  854. var attList = [
  855. 'clipPath',
  856. 'colorProfile',
  857. 'src',
  858. 'cursor',
  859. 'fill',
  860. 'filter',
  861. 'marker',
  862. 'markerStart',
  863. 'markerMid',
  864. 'markerEnd',
  865. 'mask',
  866. 'stroke',
  867. 'style'
  868. ];
  869. var attSelector = attList.map(function (attr) { return ("[" + attr + "]"); }).join(',');
  870. /**
  871. * Update URLs in svg image (like `fill="url(...)"`) and update referencing elements
  872. * @param {Element} svg
  873. * @param {NodeList} references
  874. * @param {string|RegExp} startsWith
  875. * @param {string} replaceWith
  876. * @return {void}
  877. *
  878. * @example
  879. * const sprite = document.querySelector('svg.sprite');
  880. * const usages = document.querySelectorAll('use');
  881. * updateUrls(sprite, usages, '#', 'prefix#');
  882. */
  883. var updateUrls = function (svg, references, startsWith, replaceWith) {
  884. var startsWithEncoded = encoder(startsWith);
  885. var replaceWithEncoded = encoder(replaceWith);
  886. var nodes = svg.querySelectorAll(attSelector);
  887. var attrs = selectAttributes(nodes, function (ref) {
  888. var localName = ref.localName;
  889. var value = ref.value;
  890. return attList.indexOf(localName) !== -1 && value.indexOf(("url(" + startsWithEncoded)) !== -1;
  891. });
  892. attrs.forEach(function (attr) { return attr.value = attr.value.replace(new RegExp(escapeRegExp(startsWithEncoded), 'g'), replaceWithEncoded); });
  893. updateReferences(references, startsWithEncoded, replaceWithEncoded);
  894. };
  895. /**
  896. * Internal emitter events
  897. * @enum
  898. * @private
  899. */
  900. var Events = {
  901. MOUNT: 'mount',
  902. SYMBOL_MOUNT: 'symbol_mount'
  903. };
  904. var BrowserSprite = (function (Sprite$$1) {
  905. function BrowserSprite(cfg) {
  906. var this$1 = this;
  907. if ( cfg === void 0 ) cfg = {};
  908. Sprite$$1.call(this, deepmerge(defaultConfig$1, cfg));
  909. var emitter = mitt();
  910. this._emitter = emitter;
  911. this.node = null;
  912. var ref = this;
  913. var config = ref.config;
  914. if (config.autoConfigure) {
  915. this._autoConfigure(cfg);
  916. }
  917. if (config.syncUrlsWithBaseTag) {
  918. var baseUrl = document.getElementsByTagName('base')[0].getAttribute('href');
  919. emitter.on(Events.MOUNT, function () { return this$1.updateUrls('#', baseUrl); });
  920. }
  921. var handleLocationChange = this._handleLocationChange.bind(this);
  922. this._handleLocationChange = handleLocationChange;
  923. // Provide way to update sprite urls externally via dispatching custom window event
  924. if (config.listenLocationChangeEvent) {
  925. window.addEventListener(config.locationChangeEvent, handleLocationChange);
  926. }
  927. // Emit location change event in Angular automatically
  928. if (config.locationChangeAngularEmitter) {
  929. locationChangeAngularEmitter(config.locationChangeEvent);
  930. }
  931. // After sprite mounted
  932. emitter.on(Events.MOUNT, function (spriteNode) {
  933. if (config.moveGradientsOutsideSymbol) {
  934. moveGradientsOutsideSymbol(spriteNode);
  935. }
  936. });
  937. // After symbol mounted into sprite
  938. emitter.on(Events.SYMBOL_MOUNT, function (symbolNode) {
  939. if (config.moveGradientsOutsideSymbol) {
  940. moveGradientsOutsideSymbol(symbolNode.parentNode);
  941. }
  942. if (browser.isIE() || browser.isEdge()) {
  943. evalStylesIEWorkaround(symbolNode);
  944. }
  945. });
  946. }
  947. if ( Sprite$$1 ) BrowserSprite.__proto__ = Sprite$$1;
  948. BrowserSprite.prototype = Object.create( Sprite$$1 && Sprite$$1.prototype );
  949. BrowserSprite.prototype.constructor = BrowserSprite;
  950. var prototypeAccessors = { isMounted: {} };
  951. /**
  952. * @return {boolean}
  953. */
  954. prototypeAccessors.isMounted.get = function () {
  955. return !!this.node;
  956. };
  957. /**
  958. * Automatically configure following options
  959. * - `syncUrlsWithBaseTag`
  960. * - `locationChangeAngularEmitter`
  961. * - `moveGradientsOutsideSymbol`
  962. * @param {Object} cfg
  963. * @private
  964. */
  965. BrowserSprite.prototype._autoConfigure = function _autoConfigure (cfg) {
  966. var ref = this;
  967. var config = ref.config;
  968. if (typeof cfg.syncUrlsWithBaseTag === 'undefined') {
  969. config.syncUrlsWithBaseTag = typeof document.getElementsByTagName('base')[0] !== 'undefined';
  970. }
  971. if (typeof cfg.locationChangeAngularEmitter === 'undefined') {
  972. config.locationChangeAngularEmitter = 'angular' in window;
  973. }
  974. if (typeof cfg.moveGradientsOutsideSymbol === 'undefined') {
  975. config.moveGradientsOutsideSymbol = browser.isFirefox();
  976. }
  977. };
  978. /**
  979. * @param {Event} event
  980. * @param {Object} event.detail
  981. * @param {string} event.detail.oldUrl
  982. * @param {string} event.detail.newUrl
  983. * @private
  984. */
  985. BrowserSprite.prototype._handleLocationChange = function _handleLocationChange (event) {
  986. var ref = event.detail;
  987. var oldUrl = ref.oldUrl;
  988. var newUrl = ref.newUrl;
  989. this.updateUrls(oldUrl, newUrl);
  990. };
  991. /**
  992. * Add new symbol. If symbol with the same id exists it will be replaced.
  993. * If sprite already mounted - `symbol.mount(sprite.node)` will be called.
  994. * @fires Events#SYMBOL_MOUNT
  995. * @param {BrowserSpriteSymbol} symbol
  996. * @return {boolean} `true` - symbol was added, `false` - replaced
  997. */
  998. BrowserSprite.prototype.add = function add (symbol) {
  999. var sprite = this;
  1000. var isNewSymbol = Sprite$$1.prototype.add.call(this, symbol);
  1001. if (this.isMounted && isNewSymbol) {
  1002. symbol.mount(sprite.node);
  1003. this._emitter.emit(Events.SYMBOL_MOUNT, symbol.node);
  1004. }
  1005. return isNewSymbol;
  1006. };
  1007. /**
  1008. * Attach to existing DOM node
  1009. * @param {string|Element} target
  1010. * @return {Element|null} attached DOM Element. null if node to attach not found.
  1011. */
  1012. BrowserSprite.prototype.attach = function attach (target) {
  1013. var this$1 = this;
  1014. var sprite = this;
  1015. if (sprite.isMounted) {
  1016. return sprite.node;
  1017. }
  1018. /** @type Element */
  1019. var node = typeof target === 'string' ? document.querySelector(target) : target;
  1020. sprite.node = node;
  1021. // Already added symbols needs to be mounted
  1022. this.symbols.forEach(function (symbol) {
  1023. symbol.mount(sprite.node);
  1024. this$1._emitter.emit(Events.SYMBOL_MOUNT, symbol.node);
  1025. });
  1026. // Create symbols from existing DOM nodes, add and mount them
  1027. arrayFrom(node.querySelectorAll('symbol'))
  1028. .forEach(function (symbolNode) {
  1029. var symbol = BrowserSpriteSymbol.createFromExistingNode(symbolNode);
  1030. symbol.node = symbolNode; // hack to prevent symbol mounting to sprite when adding
  1031. sprite.add(symbol);
  1032. });
  1033. this._emitter.emit(Events.MOUNT, node);
  1034. return node;
  1035. };
  1036. BrowserSprite.prototype.destroy = function destroy () {
  1037. var ref = this;
  1038. var config = ref.config;
  1039. var symbols = ref.symbols;
  1040. var _emitter = ref._emitter;
  1041. symbols.forEach(function (s) { return s.destroy(); });
  1042. _emitter.off('*');
  1043. window.removeEventListener(config.locationChangeEvent, this._handleLocationChange);
  1044. if (this.isMounted) {
  1045. this.unmount();
  1046. }
  1047. };
  1048. /**
  1049. * @fires Events#MOUNT
  1050. * @param {string|Element} [target]
  1051. * @param {boolean} [prepend=false]
  1052. * @return {Element|null} rendered sprite node. null if mount node not found.
  1053. */
  1054. BrowserSprite.prototype.mount = function mount (target, prepend) {
  1055. if ( target === void 0 ) target = this.config.mountTo;
  1056. if ( prepend === void 0 ) prepend = false;
  1057. var sprite = this;
  1058. if (sprite.isMounted) {
  1059. return sprite.node;
  1060. }
  1061. var mountNode = typeof target === 'string' ? document.querySelector(target) : target;
  1062. var node = sprite.render();
  1063. this.node = node;
  1064. if (prepend && mountNode.childNodes[0]) {
  1065. mountNode.insertBefore(node, mountNode.childNodes[0]);
  1066. } else {
  1067. mountNode.appendChild(node);
  1068. }
  1069. this._emitter.emit(Events.MOUNT, node);
  1070. return node;
  1071. };
  1072. /**
  1073. * @return {Element}
  1074. */
  1075. BrowserSprite.prototype.render = function render () {
  1076. return parse(this.stringify());
  1077. };
  1078. /**
  1079. * Detach sprite from the DOM
  1080. */
  1081. BrowserSprite.prototype.unmount = function unmount () {
  1082. this.node.parentNode.removeChild(this.node);
  1083. };
  1084. /**
  1085. * Update URLs in sprite and usage elements
  1086. * @param {string} oldUrl
  1087. * @param {string} newUrl
  1088. * @return {boolean} `true` - URLs was updated, `false` - sprite is not mounted
  1089. */
  1090. BrowserSprite.prototype.updateUrls = function updateUrls$1 (oldUrl, newUrl) {
  1091. if (!this.isMounted) {
  1092. return false;
  1093. }
  1094. var usages = document.querySelectorAll(this.config.usagesToUpdate);
  1095. updateUrls(
  1096. this.node,
  1097. usages,
  1098. ((getUrlWithoutFragment(oldUrl)) + "#"),
  1099. ((getUrlWithoutFragment(newUrl)) + "#")
  1100. );
  1101. return true;
  1102. };
  1103. Object.defineProperties( BrowserSprite.prototype, prototypeAccessors );
  1104. return BrowserSprite;
  1105. }(Sprite));
  1106. var ready$1 = createCommonjsModule(function (module) {
  1107. /*!
  1108. * domready (c) Dustin Diaz 2014 - License MIT
  1109. */
  1110. !function (name, definition) {
  1111. { module.exports = definition(); }
  1112. }('domready', function () {
  1113. var fns = [], listener
  1114. , doc = document
  1115. , hack = doc.documentElement.doScroll
  1116. , domContentLoaded = 'DOMContentLoaded'
  1117. , loaded = (hack ? /^loaded|^c/ : /^loaded|^i|^c/).test(doc.readyState);
  1118. if (!loaded)
  1119. { doc.addEventListener(domContentLoaded, listener = function () {
  1120. doc.removeEventListener(domContentLoaded, listener);
  1121. loaded = 1;
  1122. while (listener = fns.shift()) { listener(); }
  1123. }); }
  1124. return function (fn) {
  1125. loaded ? setTimeout(fn, 0) : fns.push(fn);
  1126. }
  1127. });
  1128. });
  1129. var spriteNodeId = '__SVG_SPRITE_NODE__';
  1130. var spriteGlobalVarName = '__SVG_SPRITE__';
  1131. var isSpriteExists = !!window[spriteGlobalVarName];
  1132. // eslint-disable-next-line import/no-mutable-exports
  1133. var sprite;
  1134. if (isSpriteExists) {
  1135. sprite = window[spriteGlobalVarName];
  1136. } else {
  1137. sprite = new BrowserSprite({ attrs: { id: spriteNodeId } });
  1138. window[spriteGlobalVarName] = sprite;
  1139. }
  1140. var loadSprite = function () {
  1141. /**
  1142. * Check for page already contains sprite node
  1143. * If found - attach to and reuse it's content
  1144. * If not - render and mount the new sprite
  1145. */
  1146. var existing = document.getElementById(spriteNodeId);
  1147. if (existing) {
  1148. sprite.attach(existing);
  1149. } else {
  1150. sprite.mount(document.body, true);
  1151. }
  1152. };
  1153. if (document.body) {
  1154. loadSprite();
  1155. } else {
  1156. ready$1(loadSprite);
  1157. }
  1158. var sprite$1 = sprite;
  1159. return sprite$1;
  1160. })));
  1161. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0)))
  1162. /***/ })
  1163. /******/ ]);