{"version":3,"sources":["webpack://[name]/./src/js/components/SVGInjectComponent.js","webpack://[name]/./node_modules/@iconfu/svg-inject/dist/svg-inject.js"],"names":["SVGInjectComponent","_BaseComponent","element","_this","_classCallCheck","_callSuper","SVGInject","_inherits","_createClass","BaseComponent","window","document","xmlSerializer","domParser","ID_SUFFIX_REGEX","RegExp","ID_SUFFIX","ATTRIBUTE_EXCLUSION_NAMES","A_ELEMENT","IS_SVG_SUPPORTED","SVGRect","DEFAULT_OPTIONS","useCache","copyAttributes","makeIdsUnique","IRI_TAG_PROPERTIES_MAP","clipPath","cursor","filter","linearGradient","marker","mask","pattern","radialGradient","uniqueIdCounter","svgElemToSvgString","svgElement","XMLSerializer","serializeToString","svgElem","onlyReferenced","idElem","tagName","i","j","idSuffix","funcIriRegex","idElements","querySelectorAll","referencedIds","iriTagNames","iriProperties","changed","localName","forEach","mappedProperty","indexOf","push","propertyName","value","newValue","descElements","textContent","replace","match","id","hasAttributes","refAttrName","iri","test","trim","substring","inject","imgElem","absUrl","options","parentNode","attribute","attributeName","attributeValue","attributes","name","titleElem","firstElementChild","toLowerCase","insertBefore","beforeInject","injectElem","replaceChild","removeOnLoadAttribute","afterInject","svgInvalid","mergeOptions","mergedOptions","args","arguments","argument","key","hasOwnProperty","buildSvgElement","svgStr","verify","svgDoc","DOMParser","parseFromString","svgStringToSvgDoc","e","documentElement","div","createElement","innerHTML","removeAttribute","errorMessage","msg","console","error","fail","status","onFail","svgNotSupported","loadFail","removeEventListeners","onload","onerror","imgNotSet","SVGInjectInstance","createSVGInject","globalName","defaultOptions","svgLoadCache","img","run","resolve","allFinish","onAllFinish","injectIndex","injectCount","finish","SVGInjectElement","Promise","callback","svgInjectAttributeValue","Array","isArray","beforeLoad","src","onFinishCallbacks","onFinish","onFinishCallback","url","href","useCacheOption","makeIdsUniqueOption","setSvgLoadCacheValue","val","svgLoad","handleLoadValue","loadValue","hasUniqueIds","svgString","uniqueIdsSvgString","makeIdsUniqueCached","isCallbackQueue","errorCallback","req","XMLHttpRequest","onreadystatechange","readyState","responseXML","responseText","open","send","loadSvg","svgXml","Document","afterLoad","svgElemOrSvgString","isString","SVGElement","css","head","style","type","appendChild","createTextNode","addStyleToHead","setOptions","create","err","fallbackSrc","module","exports"],"mappings":"6fAC2C,IAEtBA,EAAkB,SAAAC,GACrC,SAAAD,EAAYE,GAAS,IAAAC,EAEA,OAFAC,IAAA,KAAAJ,GACnBG,EAAAE,EAAA,KAAAL,EAAA,CAAME,IACNI,IAAUJ,GAASC,EACpB,OAAAI,IAAAP,EAAAC,GAAAO,IAAAR,GAJoC,CAASS,M;;;;;;;;;;CCOhD,SAAUC,EAAQC,GAEhB,IA2CIC,EACAC,EA9BAC,EAAkB,IAAIC,OAAOC,gBAAoB,KAIjDC,EAA4B,CAAC,MAAO,MAAO,SAAU,WACrDC,EAAYP,EAAyB,cAAE,KACvCQ,EAfc,oBAeYC,QAC1BC,EAAkB,CACpBC,UAAU,EACVC,gBAAgB,EAChBC,eAAe,GAIbC,EAAyB,CAC3BC,SAAU,CAAC,aACX,gBArBS,KAsBTC,OAtBS,KAuBTC,OAvBS,KAwBTC,eAAgB,CAAC,OAAQ,UACzBC,OAAQ,CAAC,SAAU,aAAc,aAAc,gBAC/CC,KA1BS,KA2BTC,QAAS,CAAC,OAAQ,UAClBC,eAAgB,CAAC,OAAQ,WAKvBC,EAAkB,EAatB,SAASC,EAAmBC,GAE1B,OADAxB,EAAgBA,GAAiB,IAAIyB,eAChBC,kBAAkBF,GA+EzC,SAASZ,EAAce,EAASC,GAC9B,IAOIC,EAIAC,EAIAC,EAAGC,EAfHC,EA5HU,YA4HaX,IAGvBY,EAAe,kCAGfC,EAAaR,EAAQS,iBAAiB,QAItCC,EAAgBT,EAAiB,GA1I5B,KA4ILU,EAAc,GACdC,EAAgB,GAChBC,GAAU,EAGd,GAAIL,EAAmB,OAAG,CAGxB,IAAKJ,EAAI,EAAGA,EAAII,EAAmB,OAAGJ,KACpCD,EAAUK,EAAWJ,GAAGU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ACC,WACD3B,EAAS/C,EAASE,GAClB8E,EAtlBM,aAulBNN,aAWJvB,IAnjBN,IAAwByB,EAsmBtB,OAjSIlI,GAxFN,SAAwBgK,GACtB,IAAIC,EAAOzK,EAAmC,qBAAE,QAAQ,GACxD,GAAIyK,EAAM,CACR,IAAIC,EAAQ1K,EAAyB,cA3S3B,SA4SV0K,EAAMC,KAAO,WACbD,EAAME,YAAY5K,EAAS6K,eAAeL,IAC1CC,EAAKG,YAAYF,IAqFjBI,CAAe,gBAAkB1D,EAAa,2BAqPhDzH,EAAUoL,WAAa,SAAS/G,GAC9BqD,EAAiBpC,EAAaoC,EAAgBrD,IAKhDrE,EAAUqL,OAAS7D,EAYnBxH,EAAUsL,IAAM,SAAS1D,EAAK2D,GACxB3D,EAtmBG,GAumBDA,EAAe,cACjBT,EAAqBS,GAEhB/G,GAGHsE,EAAsByC,GACtBV,EAASU,EAAKF,IAHdT,EAAgBW,EAAKF,GAKnB6D,IACFpG,EAAsByC,GACtBA,EAAIe,IAAM4C,IAIdjE,KAIJlH,EAAOqH,GAAczH,EAEdA,EAGewH,CAAgB,aAEkB,iBAAlBgE,EAAOC,UAC7CD,EAAOC,QAAUlE,GA5qBrB,CA8qBGnH,OAAQC","file":"js/component-SVGInjectComponent-js.chunks.js","sourcesContent":["import BaseComponent from '../abstracts/BaseComponent';\nimport SVGInject from '@iconfu/svg-inject';\n\nexport default class SVGInjectComponent extends BaseComponent {\n constructor(element) {\n super(element);\n SVGInject(element);\n }\n}\n","/**\n * SVGInject - Version 1.2.3\n * A tiny, intuitive, robust, caching solution for injecting SVG files inline into the DOM.\n *\n * https://github.com/iconfu/svg-inject\n *\n * Copyright (c) 2018 INCORS, the creators of iconfu.com\n * @license MIT License - https://github.com/iconfu/svg-inject/blob/master/LICENSE\n */\n\n(function(window, document) {\n // constants for better minification\n var _CREATE_ELEMENT_ = 'createElement';\n var _GET_ELEMENTS_BY_TAG_NAME_ = 'getElementsByTagName';\n var _LENGTH_ = 'length';\n var _STYLE_ = 'style';\n var _TITLE_ = 'title';\n var _UNDEFINED_ = 'undefined';\n var _SET_ATTRIBUTE_ = 'setAttribute';\n var _GET_ATTRIBUTE_ = 'getAttribute';\n\n var NULL = null;\n\n // constants\n var __SVGINJECT = '__svgInject';\n var ID_SUFFIX = '--inject-';\n var ID_SUFFIX_REGEX = new RegExp(ID_SUFFIX + '\\\\d+', \"g\");\n var LOAD_FAIL = 'LOAD_FAIL';\n var SVG_NOT_SUPPORTED = 'SVG_NOT_SUPPORTED';\n var SVG_INVALID = 'SVG_INVALID';\n var ATTRIBUTE_EXCLUSION_NAMES = ['src', 'alt', 'onload', 'onerror'];\n var A_ELEMENT = document[_CREATE_ELEMENT_]('a');\n var IS_SVG_SUPPORTED = typeof SVGRect != _UNDEFINED_;\n var DEFAULT_OPTIONS = {\n useCache: true,\n copyAttributes: true,\n makeIdsUnique: true\n };\n // Map of IRI referenceable tag names to properties that can reference them. This is defined in\n // https://www.w3.org/TR/SVG11/linking.html#processingIRI\n var IRI_TAG_PROPERTIES_MAP = {\n clipPath: ['clip-path'],\n 'color-profile': NULL,\n cursor: NULL,\n filter: NULL,\n linearGradient: ['fill', 'stroke'],\n marker: ['marker', 'marker-end', 'marker-mid', 'marker-start'],\n mask: NULL,\n pattern: ['fill', 'stroke'],\n radialGradient: ['fill', 'stroke']\n };\n var INJECTED = 1;\n var FAIL = 2;\n\n var uniqueIdCounter = 1;\n var xmlSerializer;\n var domParser;\n\n\n // creates an SVG document from an SVG string\n function svgStringToSvgDoc(svgStr) {\n domParser = domParser || new DOMParser();\n return domParser.parseFromString(svgStr, 'text/xml');\n }\n\n\n // searializes an SVG element to an SVG string\n function svgElemToSvgString(svgElement) {\n xmlSerializer = xmlSerializer || new XMLSerializer();\n return xmlSerializer.serializeToString(svgElement);\n }\n\n\n // Returns the absolute url for the specified url\n function getAbsoluteUrl(url) {\n A_ELEMENT.href = url;\n return A_ELEMENT.href;\n }\n\n\n // Load svg with an XHR request\n function loadSvg(url, callback, errorCallback) {\n if (url) {\n var req = new XMLHttpRequest();\n req.onreadystatechange = function() {\n if (req.readyState == 4) {\n // readyState is DONE\n var status = req.status;\n if (status == 200) {\n // request status is OK\n callback(req.responseXML, req.responseText.trim());\n } else if (status >= 400) {\n // request status is error (4xx or 5xx)\n errorCallback();\n } else if (status == 0) {\n // request status 0 can indicate a failed cross-domain call\n errorCallback();\n }\n }\n };\n req.open('GET', url, true);\n req.send();\n }\n }\n\n\n // Copy attributes from img element to svg element\n function copyAttributes(imgElem, svgElem) {\n var attribute;\n var attributeName;\n var attributeValue;\n var attributes = imgElem.attributes;\n for (var i = 0; i < attributes[_LENGTH_]; i++) {\n attribute = attributes[i];\n attributeName = attribute.name;\n // Only copy attributes not explicitly excluded from copying\n if (ATTRIBUTE_EXCLUSION_NAMES.indexOf(attributeName) == -1) {\n attributeValue = attribute.value;\n // If img attribute is \"title\", insert a title element into SVG element\n if (attributeName == _TITLE_) {\n var titleElem;\n var firstElementChild = svgElem.firstElementChild;\n if (firstElementChild && firstElementChild.localName.toLowerCase() == _TITLE_) {\n // If the SVG element's first child is a title element, keep it as the title element\n titleElem = firstElementChild;\n } else {\n // If the SVG element's first child element is not a title element, create a new title\n // ele,emt and set it as the first child\n titleElem = document[_CREATE_ELEMENT_ + 'NS']('http://www.w3.org/2000/svg', _TITLE_);\n svgElem.insertBefore(titleElem, firstElementChild);\n }\n // Set new title content\n titleElem.textContent = attributeValue;\n } else {\n // Set img attribute to svg element\n svgElem[_SET_ATTRIBUTE_](attributeName, attributeValue);\n }\n }\n }\n }\n\n\n // This function appends a suffix to IDs of referenced elements in the <defs> in order to to avoid ID collision\n // between multiple injected SVGs. The suffix has the form \"--inject-X\", where X is a running number which is\n // incremented with each injection. References to the IDs are adjusted accordingly.\n // We assume tha all IDs within the injected SVG are unique, therefore the same suffix can be used for all IDs of one\n // injected SVG.\n // If the onlyReferenced argument is set to true, only those IDs will be made unique that are referenced from within the SVG\n function makeIdsUnique(svgElem, onlyReferenced) {\n var idSuffix = ID_SUFFIX + uniqueIdCounter++;\n // Regular expression for functional notations of an IRI references. This will find occurences in the form\n // url(#anyId) or url(\"#anyId\") (for Internet Explorer) and capture the referenced ID\n var funcIriRegex = /url\\(\"?#([a-zA-Z][\\w:.-]*)\"?\\)/g;\n // Get all elements with an ID. The SVG spec recommends to put referenced elements inside <defs> elements, but\n // this is not a requirement, therefore we have to search for IDs in the whole SVG.\n var idElements = svgElem.querySelectorAll('[id]');\n var idElem;\n // An object containing referenced IDs as keys is used if only referenced IDs should be uniquified.\n // If this object does not exist, all IDs will be uniquified.\n var referencedIds = onlyReferenced ? [] : NULL;\n var tagName;\n var iriTagNames = {};\n var iriProperties = [];\n var changed = false;\n var i, j;\n\n if (idElements[_LENGTH_]) {\n // Make all IDs unique by adding the ID suffix and collect all encountered tag names\n // that are IRI referenceable from properities.\n for (i = 0; i < idElements[_LENGTH_]; i++) {\n tagName = idElements[i].localName; // Use non-namespaced tag name\n // Make ID unique if tag name is IRI referenceable\n if (tagName in IRI_TAG_PROPERTIES_MAP) {\n iriTagNames[tagName] = 1;\n }\n }\n // Get all properties that are mapped to the found IRI referenceable tags\n for (tagName in iriTagNames) {\n (IRI_TAG_PROPERTIES_MAP[tagName] || [tagName]).forEach(function (mappedProperty) {\n // Add mapped properties to array of iri referencing properties.\n // Use linear search here because the number of possible entries is very small (maximum 11)\n if (iriProperties.indexOf(mappedProperty) < 0) {\n iriProperties.push(mappedProperty);\n }\n });\n }\n if (iriProperties[_LENGTH_]) {\n // Add \"style\" to properties, because it may contain references in the form 'style=\"fill:url(#myFill)\"'\n iriProperties.push(_STYLE_);\n }\n // Run through all elements of the SVG and replace IDs in references.\n // To get all descending elements, getElementsByTagName('*') seems to perform faster than querySelectorAll('*').\n // Since svgElem.getElementsByTagName('*') does not return the svg element itself, we have to handle it separately.\n var descElements = svgElem[_GET_ELEMENTS_BY_TAG_NAME_]('*');\n var element = svgElem;\n var propertyName;\n var value;\n var newValue;\n for (i = -1; element != NULL;) {\n if (element.localName == _STYLE_) {\n // If element is a style element, replace IDs in all occurences of \"url(#anyId)\" in text content\n value = element.textContent;\n newValue = value && value.replace(funcIriRegex, function(match, id) {\n if (referencedIds) {\n referencedIds[id] = 1;\n }\n return 'url(#' + id + idSuffix + ')';\n });\n if (newValue !== value) {\n element.textContent = newValue;\n }\n } else if (element.hasAttributes()) {\n // Run through all property names for which IDs were found\n for (j = 0; j < iriProperties[_LENGTH_]; j++) {\n propertyName = iriProperties[j];\n value = element[_GET_ATTRIBUTE_](propertyName);\n newValue = value && value.replace(funcIriRegex, function(match, id) {\n if (referencedIds) {\n referencedIds[id] = 1;\n }\n return 'url(#' + id + idSuffix + ')';\n });\n if (newValue !== value) {\n element[_SET_ATTRIBUTE_](propertyName, newValue);\n }\n }\n // Replace IDs in xlink:ref and href attributes\n ['xlink:href', 'href'].forEach(function(refAttrName) {\n var iri = element[_GET_ATTRIBUTE_](refAttrName);\n if (/^\\s*#/.test(iri)) { // Check if iri is non-null and internal reference\n iri = iri.trim();\n element[_SET_ATTRIBUTE_](refAttrName, iri + idSuffix);\n if (referencedIds) {\n // Add ID to referenced IDs\n referencedIds[iri.substring(1)] = 1;\n }\n }\n });\n }\n element = descElements[++i];\n }\n for (i = 0; i < idElements[_LENGTH_]; i++) {\n idElem = idElements[i];\n // If set of referenced IDs exists, make only referenced IDs unique,\n // otherwise make all IDs unique.\n if (!referencedIds || referencedIds[idElem.id]) {\n // Add suffix to element's ID\n idElem.id += idSuffix;\n changed = true;\n }\n }\n }\n // return true if SVG element has changed\n return changed;\n }\n\n\n // For cached SVGs the IDs are made unique by simply replacing the already inserted unique IDs with a\n // higher ID counter. This is much more performant than a call to makeIdsUnique().\n function makeIdsUniqueCached(svgString) {\n return svgString.replace(ID_SUFFIX_REGEX, ID_SUFFIX + uniqueIdCounter++);\n }\n\n\n // Inject SVG by replacing the img element with the SVG element in the DOM\n function inject(imgElem, svgElem, absUrl, options) {\n if (svgElem) {\n svgElem[_SET_ATTRIBUTE_]('data-inject-url', absUrl);\n var parentNode = imgElem.parentNode;\n if (parentNode) {\n if (options.copyAttributes) {\n copyAttributes(imgElem, svgElem);\n }\n // Invoke beforeInject hook if set\n var beforeInject = options.beforeInject;\n var injectElem = (beforeInject && beforeInject(imgElem, svgElem)) || svgElem;\n // Replace img element with new element. This is the actual injection.\n parentNode.replaceChild(injectElem, imgElem);\n // Mark img element as injected\n imgElem[__SVGINJECT] = INJECTED;\n removeOnLoadAttribute(imgElem);\n // Invoke afterInject hook if set\n var afterInject = options.afterInject;\n if (afterInject) {\n afterInject(imgElem, injectElem);\n }\n }\n } else {\n svgInvalid(imgElem, options);\n }\n }\n\n\n // Merges any number of options objects into a new object\n function mergeOptions() {\n var mergedOptions = {};\n var args = arguments;\n // Iterate over all specified options objects and add all properties to the new options object\n for (var i = 0; i < args[_LENGTH_]; i++) {\n var argument = args[i];\n for (var key in argument) {\n if (argument.hasOwnProperty(key)) {\n mergedOptions[key] = argument[key];\n }\n }\n }\n return mergedOptions;\n }\n\n\n // Adds the specified CSS to the document's <head> element\n function addStyleToHead(css) {\n var head = document[_GET_ELEMENTS_BY_TAG_NAME_]('head')[0];\n if (head) {\n var style = document[_CREATE_ELEMENT_](_STYLE_);\n style.type = 'text/css';\n style.appendChild(document.createTextNode(css));\n head.appendChild(style);\n }\n }\n\n\n // Builds an SVG element from the specified SVG string\n function buildSvgElement(svgStr, verify) {\n if (verify) {\n var svgDoc;\n try {\n // Parse the SVG string with DOMParser\n svgDoc = svgStringToSvgDoc(svgStr);\n } catch(e) {\n return NULL;\n }\n if (svgDoc[_GET_ELEMENTS_BY_TAG_NAME_]('parsererror')[_LENGTH_]) {\n // DOMParser does not throw an exception, but instead puts parsererror tags in the document\n return NULL;\n }\n return svgDoc.documentElement;\n } else {\n var div = document.createElement('div');\n div.innerHTML = svgStr;\n return div.firstElementChild;\n }\n }\n\n\n function removeOnLoadAttribute(imgElem) {\n // Remove the onload attribute. Should only be used to remove the unstyled image flash protection and\n // make the element visible, not for removing the event listener.\n imgElem.removeAttribute('onload');\n }\n\n\n function errorMessage(msg) {\n console.error('SVGInject: ' + msg);\n }\n\n\n function fail(imgElem, status, options) {\n imgElem[__SVGINJECT] = FAIL;\n if (options.onFail) {\n options.onFail(imgElem, status);\n } else {\n errorMessage(status);\n }\n }\n\n\n function svgInvalid(imgElem, options) {\n removeOnLoadAttribute(imgElem);\n fail(imgElem, SVG_INVALID, options);\n }\n\n\n function svgNotSupported(imgElem, options) {\n removeOnLoadAttribute(imgElem);\n fail(imgElem, SVG_NOT_SUPPORTED, options);\n }\n\n\n function loadFail(imgElem, options) {\n fail(imgElem, LOAD_FAIL, options);\n }\n\n\n function removeEventListeners(imgElem) {\n imgElem.onload = NULL;\n imgElem.onerror = NULL;\n }\n\n\n function imgNotSet(msg) {\n errorMessage('no img element');\n }\n\n\n function createSVGInject(globalName, options) {\n var defaultOptions = mergeOptions(DEFAULT_OPTIONS, options);\n var svgLoadCache = {};\n\n if (IS_SVG_SUPPORTED) {\n // If the browser supports SVG, add a small stylesheet that hides the <img> elements until\n // injection is finished. This avoids showing the unstyled SVGs before style is applied.\n addStyleToHead('img[onload^=\"' + globalName + '(\"]{visibility:hidden;}');\n }\n\n\n /**\n * SVGInject\n *\n * Injects the SVG specified in the `src` attribute of the specified `img` element or array of `img`\n * elements. Returns a Promise object which resolves if all passed in `img` elements have either been\n * injected or failed to inject (Only if a global Promise object is available like in all modern browsers\n * or through a polyfill).\n *\n * Options:\n * useCache: If set to `true` the SVG will be cached using the absolute URL. Default value is `true`.\n * copyAttributes: If set to `true` the attributes will be copied from `img` to `svg`. Dfault value\n * is `true`.\n * makeIdsUnique: If set to `true` the ID of elements in the `<defs>` element that can be references by\n * property values (for example 'clipPath') are made unique by appending \"--inject-X\", where X is a\n * running number which increases with each injection. This is done to avoid duplicate IDs in the DOM.\n * beforeLoad: Hook before SVG is loaded. The `img` element is passed as a parameter. If the hook returns\n * a string it is used as the URL instead of the `img` element's `src` attribute.\n * afterLoad: Hook after SVG is loaded. The loaded `svg` element and `svg` string are passed as a\n * parameters. If caching is active this hook will only get called once for injected SVGs with the\n * same absolute path. Changes to the `svg` element in this hook will be applied to all injected SVGs\n * with the same absolute path. It's also possible to return an `svg` string or `svg` element which\n * will then be used for the injection.\n * beforeInject: Hook before SVG is injected. The `img` and `svg` elements are passed as parameters. If\n * any html element is returned it gets injected instead of applying the default SVG injection.\n * afterInject: Hook after SVG is injected. The `img` and `svg` elements are passed as parameters.\n * onAllFinish: Hook after all `img` elements passed to an SVGInject() call have either been injected or\n * failed to inject.\n * onFail: Hook after injection fails. The `img` element and a `status` string are passed as an parameter.\n * The `status` can be either `'SVG_NOT_SUPPORTED'` (the browser does not support SVG),\n * `'SVG_INVALID'` (the SVG is not in a valid format) or `'LOAD_FAILED'` (loading of the SVG failed).\n *\n * @param {HTMLImageElement} img - an img element or an array of img elements\n * @param {Object} [options] - optional parameter with [options](#options) for this injection.\n */\n function SVGInject(img, options) {\n options = mergeOptions(defaultOptions, options);\n\n var run = function(resolve) {\n var allFinish = function() {\n var onAllFinish = options.onAllFinish;\n if (onAllFinish) {\n onAllFinish();\n }\n resolve && resolve();\n };\n\n if (img && typeof img[_LENGTH_] != _UNDEFINED_) {\n // an array like structure of img elements\n var injectIndex = 0;\n var injectCount = img[_LENGTH_];\n\n if (injectCount == 0) {\n allFinish();\n } else {\n var finish = function() {\n if (++injectIndex == injectCount) {\n allFinish();\n }\n };\n\n for (var i = 0; i < injectCount; i++) {\n SVGInjectElement(img[i], options, finish);\n }\n }\n } else {\n // only one img element\n SVGInjectElement(img, options, allFinish);\n }\n };\n\n // return a Promise object if globally available\n return typeof Promise == _UNDEFINED_ ? run() : new Promise(run);\n }\n\n\n // Injects a single svg element. Options must be already merged with the default options.\n function SVGInjectElement(imgElem, options, callback) {\n if (imgElem) {\n var svgInjectAttributeValue = imgElem[__SVGINJECT];\n if (!svgInjectAttributeValue) {\n removeEventListeners(imgElem);\n\n if (!IS_SVG_SUPPORTED) {\n svgNotSupported(imgElem, options);\n callback();\n return;\n }\n // Invoke beforeLoad hook if set. If the beforeLoad returns a value use it as the src for the load\n // URL path. Else use the imgElem's src attribute value.\n var beforeLoad = options.beforeLoad;\n var src = (beforeLoad && beforeLoad(imgElem)) || imgElem[_GET_ATTRIBUTE_]('src');\n\n if (!src) {\n // If no image src attribute is set do no injection. This can only be reached by using javascript\n // because if no src attribute is set the onload and onerror events do not get called\n if (src === '') {\n loadFail(imgElem, options);\n }\n callback();\n return;\n }\n\n // set array so later calls can register callbacks\n var onFinishCallbacks = [];\n imgElem[__SVGINJECT] = onFinishCallbacks;\n\n var onFinish = function() {\n callback();\n onFinishCallbacks.forEach(function(onFinishCallback) {\n onFinishCallback();\n });\n };\n\n var absUrl = getAbsoluteUrl(src);\n var useCacheOption = options.useCache;\n var makeIdsUniqueOption = options.makeIdsUnique;\n \n var setSvgLoadCacheValue = function(val) {\n if (useCacheOption) {\n svgLoadCache[absUrl].forEach(function(svgLoad) {\n svgLoad(val);\n });\n svgLoadCache[absUrl] = val;\n }\n };\n\n if (useCacheOption) {\n var svgLoad = svgLoadCache[absUrl];\n\n var handleLoadValue = function(loadValue) {\n if (loadValue === LOAD_FAIL) {\n loadFail(imgElem, options);\n } else if (loadValue === SVG_INVALID) {\n svgInvalid(imgElem, options);\n } else {\n var hasUniqueIds = loadValue[0];\n var svgString = loadValue[1];\n var uniqueIdsSvgString = loadValue[2];\n var svgElem;\n\n if (makeIdsUniqueOption) {\n if (hasUniqueIds === NULL) {\n // IDs for the SVG string have not been made unique before. This may happen if previous\n // injection of a cached SVG have been run with the option makedIdsUnique set to false\n svgElem = buildSvgElement(svgString, false);\n hasUniqueIds = makeIdsUnique(svgElem, false);\n\n loadValue[0] = hasUniqueIds;\n loadValue[2] = hasUniqueIds && svgElemToSvgString(svgElem);\n } else if (hasUniqueIds) {\n // Make IDs unique for already cached SVGs with better performance\n svgString = makeIdsUniqueCached(uniqueIdsSvgString);\n }\n }\n\n svgElem = svgElem || buildSvgElement(svgString, false);\n\n inject(imgElem, svgElem, absUrl, options);\n }\n onFinish();\n };\n\n if (typeof svgLoad != _UNDEFINED_) {\n // Value for url exists in cache\n if (svgLoad.isCallbackQueue) {\n // Same url has been cached, but value has not been loaded yet, so add to callbacks\n svgLoad.push(handleLoadValue);\n } else {\n handleLoadValue(svgLoad);\n }\n return;\n } else {\n var svgLoad = [];\n // set property isCallbackQueue to Array to differentiate from array with cached loaded values\n svgLoad.isCallbackQueue = true;\n svgLoadCache[absUrl] = svgLoad;\n }\n }\n\n // Load the SVG because it is not cached or caching is disabled\n loadSvg(absUrl, function(svgXml, svgString) {\n // Use the XML from the XHR request if it is an instance of Document. Otherwise\n // (for example of IE9), create the svg document from the svg string.\n var svgElem = svgXml instanceof Document ? svgXml.documentElement : buildSvgElement(svgString, true);\n\n var afterLoad = options.afterLoad;\n if (afterLoad) {\n // Invoke afterLoad hook which may modify the SVG element. After load may also return a new\n // svg element or svg string\n var svgElemOrSvgString = afterLoad(svgElem, svgString) || svgElem;\n if (svgElemOrSvgString) {\n // Update svgElem and svgString because of modifications to the SVG element or SVG string in\n // the afterLoad hook, so the modified SVG is also used for all later cached injections\n var isString = typeof svgElemOrSvgString == 'string';\n svgString = isString ? svgElemOrSvgString : svgElemToSvgString(svgElem);\n svgElem = isString ? buildSvgElement(svgElemOrSvgString, true) : svgElemOrSvgString;\n }\n }\n\n if (svgElem instanceof SVGElement) {\n var hasUniqueIds = NULL;\n if (makeIdsUniqueOption) {\n hasUniqueIds = makeIdsUnique(svgElem, false);\n }\n\n if (useCacheOption) {\n var uniqueIdsSvgString = hasUniqueIds && svgElemToSvgString(svgElem);\n // set an array with three entries to the load cache\n setSvgLoadCacheValue([hasUniqueIds, svgString, uniqueIdsSvgString]);\n }\n\n inject(imgElem, svgElem, absUrl, options);\n } else {\n svgInvalid(imgElem, options);\n setSvgLoadCacheValue(SVG_INVALID);\n }\n onFinish();\n }, function() {\n loadFail(imgElem, options);\n setSvgLoadCacheValue(LOAD_FAIL);\n onFinish();\n });\n } else {\n if (Array.isArray(svgInjectAttributeValue)) {\n // svgInjectAttributeValue is an array. Injection is not complete so register callback\n svgInjectAttributeValue.push(callback);\n } else {\n callback();\n }\n }\n } else {\n imgNotSet();\n }\n }\n\n\n /**\n * Sets the default [options](#options) for SVGInject.\n *\n * @param {Object} [options] - default [options](#options) for an injection.\n */\n SVGInject.setOptions = function(options) {\n defaultOptions = mergeOptions(defaultOptions, options);\n };\n\n\n // Create a new instance of SVGInject\n SVGInject.create = createSVGInject;\n\n\n /**\n * Used in onerror Event of an `<img>` element to handle cases when the loading the original src fails\n * (for example if file is not found or if the browser does not support SVG). This triggers a call to the\n * options onFail hook if available. The optional second parameter will be set as the new src attribute\n * for the img element.\n *\n * @param {HTMLImageElement} img - an img element\n * @param {String} [fallbackSrc] - optional parameter fallback src\n */\n SVGInject.err = function(img, fallbackSrc) {\n if (img) {\n if (img[__SVGINJECT] != FAIL) {\n removeEventListeners(img);\n\n if (!IS_SVG_SUPPORTED) {\n svgNotSupported(img, defaultOptions);\n } else {\n removeOnLoadAttribute(img);\n loadFail(img, defaultOptions);\n }\n if (fallbackSrc) {\n removeOnLoadAttribute(img);\n img.src = fallbackSrc;\n }\n }\n } else {\n imgNotSet();\n }\n };\n\n window[globalName] = SVGInject;\n\n return SVGInject;\n }\n\n var SVGInjectInstance = createSVGInject('SVGInject');\n\n if (typeof module == 'object' && typeof module.exports == 'object') {\n module.exports = SVGInjectInstance;\n }\n})(window, document);"],"sourceRoot":""}