UNPKG

10.9 kBJavaScriptView Raw
1!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.VueSvgInlinePlugin=t():e.VueSvgInlinePlugin=t()}(self,(function(){return function(){"use strict";var e={d:function(t,r){for(var i in r)e.o(r,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:r[i]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}},t={};e.d(t,{default:function(){return v}});var r=JSON.parse('{"u2":"vue-svg-inline-plugin","i8":"2.2.3"}');
2/**
3 * @author Oliver Findl
4 * @version 2.2.3
5 * @license MIT
6 */
7const i=r.u2;const n={directive:{name:"v-svg-inline",spriteModifierName:"sprite"},attributes:{clone:["viewbox"],merge:["class","style"],add:[{name:"focusable",value:!1},{name:"role",value:"presentation"},{name:"tabindex",value:-1}],data:[],remove:["alt","src","data-src"]},cache:{version:r.i8,persistent:!0,removeRevisions:!0},intersectionObserverOptions:{},axios:null,xhtml:!1},s="observer",o="container",a=`${i}-flags`,c=`${i}-sprite`,d=`${c}-container`,u=/.+\.svg(?:[?#].*)?$/i,l=/<svg(\s+[^>]+)?>([\s\S]+)<\/svg>/i,p=/\s*([^\s=]+)[\s=]+(?:"([^"]*)"|'([^']*)')?\s*/g,h=/^[a-z](?:[a-z0-9-:]*[a-z0-9])?$/i,f=/^v-/i,g=/\s+/g,w=/[\n\t]+/g,m=new Set([200,304]);var v={install:(e=null,t={})=>{const r="function";if(!e)throw new Error(`[${i}] Required argument is missing! [VueOrApp]`);if(![r,"object"].includes(typeof e))throw new TypeError(`[${i}] Required argument is not valid! [VueOrApp]`);if(!e.directive)throw new Error(`[${i}] Required method is missing! [VueOrApp.directive]`);if(typeof e.directive!==r)throw new TypeError(`[${i}] Required method is not valid! [VueOrApp.directive]`);if(!e.version)throw new Error(`[${i}] Required property is missing! [VueOrApp.version]`);if("string"!=typeof e.version)throw new TypeError(`[${i}] Required property is not valid! [VueOrApp.version]`);if(e.version.startsWith("1."))throw new Error(`[${i}] Vue@1 is not supported!`);["directive","attributes","cache","intersectionObserverOptions"].forEach((e=>t[e]=Object.assign({},n[e],t[e]||{}))),t=Object.assign({},n,t);for(const e in t.directive)if(t.directive[e]=t.directive[e].toString().trim().toLowerCase(),!t.directive[e]||"name"===e&&!h.test(t.directive[e]))throw new TypeError(`[${i}] Option is not valid! [options.directives.${e}="${t.directives[e]}"]`);t.directive.name=t.directive.name.replace(f,"");for(const e in t.attributes){if(!Array.isArray(t.attributes[e]))throw new TypeError(`[${i}] Option is not valid! [options.attributes.${e}=${JSON.stringify(t.attributes[e])}]`);t.attributes[e]="add"===e?t.attributes[e].map((e=>({name:e.name.toString().trim().toLowerCase(),value:e.value.toString().trim()}))):t.attributes[e].map((e=>e.toString().trim().toLowerCase())),t.attributes[e]=new Set(t.attributes[e])}for(const e in t.cache)t.cache[e]="version"===e?t.cache[e].toString().trim().toLowerCase():!!t.cache[e];t.xhtml=!!t.xhtml;const v=e.version.startsWith("3.");t._fetch="fetch"in window&&typeof fetch===r,t._axios="axios"in window&&typeof axios===r;const $=(e=null)=>!!e&&typeof e===r&&"get"in e&&typeof e.get===r;let b=!1;if(t.axios=((b=$(t.axios))?t.axios:null)||(t._axios&&"create"in axios&&typeof axios.create===r?axios.create():null),t._axios=b||$(t.axios),!t._fetch&&!t._axios)throw new Error(`[${i}] Feature is not supported by browser! [fetch || axios]`);t._observer="IntersectionObserver"in window,t._observer||console.error(`[${i}] Feature is not supported by browser! Disabling lazy processing of image nodes. [IntersectionObserver]`),t._storage="localStorage"in window,!t._storage&&t.cache.persistent&&console.error(`[${i}] Feature is not supported by browser! Disabling persistent cache of SVG files. [localStorage]`);const y=`${i}:${t.cache.version}`;t._storage&&t.cache.removeRevisions&&Object.entries(localStorage).map((e=>e.shift())).filter((e=>e.startsWith(`${i}:`)&&!e.endsWith(`:${t.cache.version}`))).forEach((e=>localStorage.removeItem(e)));const x=t._storage&&t.cache.persistent?new Map(JSON.parse(localStorage.getItem(y)||"[]")):new Map,E=new Set,S=new Map,O=()=>S.has(s)?S.get(s):(()=>{if(!t._observer)throw new Error(`[${i}] Feature is not supported by browser! [IntersectionObserver]`);if(S.has(s))throw new Error(`[${i}] Can not create image node intersection observer, intersection observer already exists!`);const e=new IntersectionObserver(((e,t)=>{for(const r of e){if(!r.isIntersecting)continue;const e=r.target;C(e),t.unobserve(e)}}),t.intersectionObserverOptions);return S.set(s,e),e})(),R=()=>S.has(o)?S.get(o):(()=>{if(S.has(o))throw new Error(`[${i}] Can not create SVG symbol container node, container node already exists!`);let e=q(`<svg xmlns="http://www.w3.org/2000/svg" id="${d}" style="display: none !important;"></svg>`);return document.body.appendChild(e),S.set(o,e=document.getElementById(d)),e})(),q=(e="")=>{if(!e)throw new Error(`[${i}] Required argument is missing! [string]`);if(!(e=e.toString().trim()).startsWith("<")||!e.endsWith(">"))throw new TypeError(`[${i}] Argument is not valid! [string="${e}"]`);return e=e.replace(w,""),document.createRange().createContextualFragment(e)},_=(e="")=>{if(!e)throw new Error(`[${i}] Required argument is missing! [string]`);e=e.toString().trim();const r=new Map;let n;for(p.lastIndex=0;n=p.exec(e);){n.index===p.lastIndex&&p.lastIndex++;const e=(n[1]||"").trim().toLowerCase();if(!e||e.startsWith("<")||e.endsWith(">"))continue;if(!h.test(e))throw new TypeError(`[${i}] Attribute name is not valid! [attribute="${e}"]`);const s=(n[2]||n[3]||"").trim();r.set(e,s||(t.xhtml?e:""))}return r},A=(e=null,r=null)=>{if(!e)throw new Error(`[${i}] Required argument is missing! [file]`);if(!r)throw new Error(`[${i}] Required argument is missing! [node]`);if(!e.path)throw new Error(`[${i}] Required property is missing! [file.path]`);if(e.path=e.path.toString().trim(),!u.test(e.path))throw new TypeError(`[${i}] Argument property is not valid! [file.path="${e.path}"]`);if(!e.content)throw new Error(`[${i}] Required property is missing! [file.content]`);if(e.content=e.content.toString().trim(),!l.test(e.content))throw new TypeError(`[${i}] Argument property is not valid! [file.content="${e.content}"]`);if(!r.outerHTML)throw new Error(`[${i}] Required property is missing! [node.outerHTML]`);return r[a].has("sprite")&&(e.content=e.content.replace(l,((r,i,n)=>{const s=E.has(e.path),o=`${c}-${s?[...E].indexOf(e.path):E.size}`;if(!s){const t=q(`<svg xmlns="http://www.w3.org/2000/svg"><symbol id="${o}"${i}>${n}</symbol></svg>`);R().appendChild(t.firstChild.firstChild),E.add(e.path)}return`<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"${t.attributes.clone.size&&(i=_(i))?` ${[...t.attributes.clone].filter((e=>!!e&&i.has(e))).map((e=>`${e}="${i.get(e)}"`)).join(" ")}`:""}><use xlink:href="#${o}" href="#${o}"></use></svg>`}))),e.content.replace(l,((e,n,s)=>{const o=_(n),a=((e=null)=>{if(!e)throw new Error(`[${i}] Required argument is missing! [namedNodeAttributeMap]`);if(!(e instanceof NamedNodeMap))throw new TypeError(`[${i}] Argument is not valid! [namedNodeAttributeMap]`);return new Map([...e].map((({name:e,value:r})=>{if(e=(e||"").trim().toLowerCase(),!h.test(e))throw new TypeError(`[${i}] Attribute name is not valid! [attribute="${e}"]`);return[e,(r=(r||"").trim())||(t.xhtml?e:"")]})))})(r.attributes);n=new Map([...o,...a]);const c=new Set(["class"]);for(const e of t.attributes.merge){const r=o.has(e)?o.get(e).split(g).filter((e=>!!e)):[],i=a.has(e)?a.get(e).split(g).filter((e=>!!e)):[];if(t.xhtml&&!r.length&&!i.length)continue;const s=[...r,...i];n.set(e,(c.has(e)?[...new Set(s)]:s).join(" ").trim())}for(const e of t.attributes.add){let r=e.value.split(g).filter((e=>!!e));if(n.has(e.name)){if(!t.attributes.merge.has(e.name))throw new Error(`[${i}] Can not add attribute, attribute already exists. [${e.name}]`);const s=n.get(e.name).split(g).filter((e=>!!e));if(t.xhtml&&!r.length&&!s.length)continue;r=[...s,...r]}n.set(e.name,(c.has(e.name)?[...new Set(r)]:r).join(" ").trim())}for(const e of t.attributes.data){if(!n.has(e))continue;let r=n.get(e).split(g).filter((e=>!!e));const s=`data-${e}`;if(n.has(s)){if(!t.attributes.merge.has(s))throw new Error(`[${i}] Can not transform attribute to data-attribute, data-attribute already exists. [${e}]`);const o=n.get(s).split(g).filter((e=>!!e));if(t.xhtml&&!r.length&&!o.length)continue;r=[...o,...r]}n.set(s,(c.has(e)?[...new Set(r)]:r).join(" ").trim()),t.attributes.remove.has(e)||t.attributes.remove.add(e)}for(const e of t.attributes.remove)n.has(e)&&n.delete(e);return`<svg${n.size?` ${[...n.keys()].filter((e=>!!e)).map((e=>`${e}="${n.get(e)}"`)).join(" ")}`:""}>${s}</svg>`}))},C=(e=null)=>{if(!e)throw new Error(`[${i}] Required argument is missing! [node]`);if(!e.dataset.src&&!e.src)throw new Error(`[${i}] Required property is missing! [node.data-src || node.src]`);e.dataset.src&&(e.dataset.src=e.dataset.src.toString().trim()),e.src&&(e.src=e.src.toString().trim()),((e="")=>{if(!t._fetch&&!t._axios)throw new Error(`[${i}] Feature is not supported by browser! [fetch || axios]`);if(!e)throw new Error(`[${i}] Required argument is missing! [path]`);if(e=e.toString().trim(),!u.test(e))throw new TypeError(`[${i}] Argument is not valid! [path="${e}"]`);return new Promise(((r,i)=>{const n={path:e};if(x.has(n.path))return n.content=x.get(n.path),r(n);(t._axios?t.axios.get:fetch)(n.path).then((e=>{if(!m.has(0|e.status))throw new Error(`Wrong response status! [response.status=${e.status}]`);return t._axios?e.data.toString():e.text()})).then((e=>(n.content=e.trim(),x.set(n.path,n.content),t._storage&&t.cache.persistent&&localStorage.setItem(y,JSON.stringify([...x])),r(n)))).catch(i)}))})(e.dataset.src||e.src).then((t=>{const r=A(t,e),n=q(r);((e=null,t=null)=>{if(!e)throw new Error(`[${i}] Required argument is missing! [node]`);if(!t)throw new Error(`[${i}] Required argument is missing! [newNode]`);if(!e.parentNode)throw new Error(`[${i}] Required property is missing! [node.parentNode]`);e.parentNode.replaceChild(t,e)})(e,n)})).catch((e=>console.error(`[${i}] ${e.toString()}`)))},N=(e=null,r=null,n=null)=>{if(!e)throw new Error(`[${i}] Required argument is missing! [node]`);if("IMG"!==e.tagName)throw new Error(`[${i}] Required argument is not valid! [node]`);if(!n)throw new Error(`[${i}] Required argument is missing! [vnode]`);if(e[a]||(e[a]=new Set),e[a].has("processed"))return;e[a].add("processed");const s=v?n.dirs:n.data.directives;if(s.length>1)throw new Error(`[${i}] Node has more than 1 directive! [${v?"vnode.dirs":"vnode.data.directives"}]`);s[0].modifiers[t.directive.spriteModifierName]&&e[a].add("sprite"),!t._observer&&e.dataset.src&&(e.src=e.dataset.src,delete e.dataset.src),e.dataset.src?O().observe(e):C(e)};e.directive(t.directive.name,v?{beforeMount:N}:{bind:N})}};return t=t.default}()}));
\No newline at end of file