const Y="vue-svg-inline-plugin",K="2.2.3",Q="Vue plugin for inline replacement of SVG images with actual content of SVG files.",Z="src/index.js",ee="src/index.d.ts",te="dist/vue-svg-inline-plugin.min.js",re="dist/vue-svg-inline-plugin.min.js",ie=["index.js","dist/*.js","src/*.{js,d.ts}"],se={example:"examples"},ne={build:"npm run remove && npm run build:modern && npm run build:default","build:default":"npm run remove:default && npx cross-env IMPORT_POLYFILLS=1 npm run webpack","build:modern":"npm run remove:modern && npm run webpack",remove:"npm run remove:default && npm run remove:modern","remove:default":"npx rimraf dist/vue-svg-inline-plugin.min.js","remove:modern":"npx rimraf dist/vue-svg-inline-plugin-modern.min.js",webpack:"npx webpack --progress --color",test:'echo "Error: no test specified" && exit 1'},ae={type:"git",url:"git+https://github.com/oliverfindl/vue-svg-inline-plugin.git"},oe=["vue","vuejs","plugin","vue-plugin","svg","inline","sprites","symbols","vue-svg-inline-plugin"],ce="Oliver Findl",le="MIT",ue={url:"https://github.com/oliverfindl/vue-svg-inline-plugin/issues"},de="https://github.com/oliverfindl/vue-svg-inline-plugin#readme",me={"core-js":"^3.25.2","intersection-observer":"^0.12.2","whatwg-fetch":"^3.6.2"},ge={"@babel/core":"^7.19.1","@babel/eslint-parser":"^7.19.1","@babel/preset-env":"^7.19.1","babel-loader":"^8.2.5","babel-plugin-remove-template-literals-whitespace":"^1.0.4","cross-env":"^7.0.3",eslint:"^8.23.1","eslint-plugin-vue":"^9.5.1","eslint-webpack-plugin":"^3.2.0",rimraf:"^3.0.2","terser-webpack-plugin":"^5.3.6",webpack:"^5.74.0","webpack-bundle-analyzer":"^4.6.1","webpack-cli":"^4.10.0"},F={name:Y,version:K,description:Q,main:Z,types:ee,unpkg:te,jsdelivr:re,files:ie,directories:se,scripts:ne,repository:ae,keywords:oe,author:ce,license:le,bugs:ue,homepage:de,dependencies:me,devDependencies:ge};/** * @author Oliver Findl * @version 2.2.3 * @license MIT */const i=F.name,he=F.version;typeof IMPORT_POLYFILLS<"u"&&IMPORT_POLYFILLS&&require("./polyfills");const L={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:he,persistent:!0,removeRevisions:!0},intersectionObserverOptions:{},axios:null,xhtml:!1},S="observer",E="container",f=`${i}-flags`,G=`${i}-sprite`,P=`${G}-${E}`,j=/.+\.svg(?:[?#].*)?$/i,I=/]+)?>([\s\S]+)<\/svg>/i,x=/\s*([^\s=]+)[\s=]+(?:"([^"]*)"|'([^']*)')?\s*/g,T=/^[a-z](?:[a-z0-9-:]*[a-z0-9])?$/i,ve=/^v-/i,p=/\s+/g,we=/[\n\t]+/g,fe=new Set([200,304]),pe=(d=null,t={})=>{const V="string",h="function",k="object";if(!d)throw new Error(`[${i}] Required argument is missing! [VueOrApp]`);if(![h,k].includes(typeof d))throw new TypeError(`[${i}] Required argument is not valid! [VueOrApp]`);if(!d.directive)throw new Error(`[${i}] Required method is missing! [VueOrApp.directive]`);if(typeof d.directive!==h)throw new TypeError(`[${i}] Required method is not valid! [VueOrApp.directive]`);if(!d.version)throw new Error(`[${i}] Required property is missing! [VueOrApp.version]`);if(typeof d.version!==V)throw new TypeError(`[${i}] Required property is not valid! [VueOrApp.version]`);if(d.version.startsWith("1."))throw new Error(`[${i}] Vue@1 is not supported!`);["directive","attributes","cache","intersectionObserverOptions"].forEach(e=>t[e]=Object.assign({},L[e],t[e]||{})),t=Object.assign({},L,t);for(const e in t.directive)if(t.directive[e]=t.directive[e].toString().trim().toLowerCase(),!t.directive[e]||e==="name"&&!T.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(ve,"");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]=e==="add"?t.attributes[e].map(n=>({name:n.name.toString().trim().toLowerCase(),value:n.value.toString().trim()})):t.attributes[e].map(n=>n.toString().trim().toLowerCase()),t.attributes[e]=new Set(t.attributes[e])}for(const e in t.cache)t.cache[e]=e==="version"?t.cache[e].toString().trim().toLowerCase():!!t.cache[e];t.xhtml=!!t.xhtml;const _=d.version.startsWith("3.");t._fetch="fetch"in window&&typeof fetch===h,t._axios="axios"in window&&typeof axios===h;const O=(e=null)=>!!e&&typeof e===h&&"get"in e&&typeof e.get===h;let A=!1;if(t.axios=((A=O(t.axios))?t.axios:null)||(t._axios&&"create"in axios&&typeof axios.create===h?axios.create():null),t._axios=A||O(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 N=`${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 $=t._storage&&t.cache.persistent?new Map(JSON.parse(localStorage.getItem(N)||"[]")):new Map,y=new Set,g=new Map,D=()=>{if(!t._observer)throw new Error(`[${i}] Feature is not supported by browser! [IntersectionObserver]`);if(g.has(S))throw new Error(`[${i}] Can not create image node intersection observer, intersection observer already exists!`);const e=new IntersectionObserver((n,a)=>{for(const r of n){if(!r.isIntersecting)continue;const o=r.target;M(o),a.unobserve(o)}},t.intersectionObserverOptions);return g.set(S,e),e},W=()=>g.has(S)?g.get(S):D(),z=()=>{if(g.has(E))throw new Error(`[${i}] Can not create SVG symbol container node, container node already exists!`);let e=R(``);return document.body.appendChild(e),g.set(E,e=document.getElementById(P)),e},X=()=>g.has(E)?g.get(E):z(),R=(e="")=>{if(!e)throw new Error(`[${i}] Required argument is missing! [string]`);if(e=e.toString().trim(),!e.startsWith("<")||!e.endsWith(">"))throw new TypeError(`[${i}] Argument is not valid! [string="${e}"]`);return e=e.replace(we,""),document.createRange().createContextualFragment(e)},B=(e=null,n=null)=>{if(!e)throw new Error(`[${i}] Required argument is missing! [node]`);if(!n)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(n,e)},C=(e="")=>{if(!e)throw new Error(`[${i}] Required argument is missing! [string]`);e=e.toString().trim();const n=new Map;x.lastIndex=0;let a;for(;a=x.exec(e);){a.index===x.lastIndex&&x.lastIndex++;const r=(a[1]||"").trim().toLowerCase();if(!r||r.startsWith("<")||r.endsWith(">"))continue;if(!T.test(r))throw new TypeError(`[${i}] Attribute name is not valid! [attribute="${r}"]`);const o=(a[2]||a[3]||"").trim();n.set(r,o||(t.xhtml?r:""))}return n},H=(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:a,value:r})=>{if(a=(a||"").trim().toLowerCase(),!T.test(a))throw new TypeError(`[${i}] Attribute name is not valid! [attribute="${a}"]`);return r=(r||"").trim(),[a,r||(t.xhtml?a:"")]}))},U=(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(),!j.test(e))throw new TypeError(`[${i}] Argument is not valid! [path="${e}"]`);return new Promise((n,a)=>{const r={path:e};if($.has(r.path))return r.content=$.get(r.path),n(r);(t._axios?t.axios.get:fetch)(r.path).then(o=>{if(!fe.has(o.status|0))throw new Error(`Wrong response status! [response.status=${o.status}]`);return t._axios?o.data.toString():o.text()}).then(o=>(r.content=o.trim(),$.set(r.path,r.content),t._storage&&t.cache.persistent&&localStorage.setItem(N,JSON.stringify([...$])),n(r))).catch(a)})},J=(e=null,n=null)=>{if(!e)throw new Error(`[${i}] Required argument is missing! [file]`);if(!n)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(),!j.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(),!I.test(e.content))throw new TypeError(`[${i}] Argument property is not valid! [file.content="${e.content}"]`);if(!n.outerHTML)throw new Error(`[${i}] Required property is missing! [node.outerHTML]`);return n[f].has("sprite")&&(e.content=e.content.replace(I,(a,r,o)=>{const w=y.has(e.path),v=`${G}-${w?[...y].indexOf(e.path):y.size}`;if(!w){const u=R(` ${o} `);X().appendChild(u.firstChild.firstChild),y.add(e.path)}return` !!u&&r.has(u)).map(u=>`${u}="${r.get(u)}"`).join(" ")}`:""}> `})),e.content.replace(I,(a,r,o)=>{const w=C(r),v=H(n.attributes);r=new Map([...w,...v]);const u=new Set(["class"]);for(const s of t.attributes.merge){const c=w.has(s)?w.get(s).split(p).filter(b=>!!b):[],l=v.has(s)?v.get(s).split(p).filter(b=>!!b):[];if(t.xhtml&&!c.length&&!l.length)continue;const m=[...c,...l];r.set(s,(u.has(s)?[...new Set(m)]:m).join(" ").trim())}for(const s of t.attributes.add){let c=s.value.split(p).filter(l=>!!l);if(r.has(s.name)){if(!t.attributes.merge.has(s.name))throw new Error(`[${i}] Can not add attribute, attribute already exists. [${s.name}]`);const l=r.get(s.name).split(p).filter(m=>!!m);if(t.xhtml&&!c.length&&!l.length)continue;c=[...l,...c]}r.set(s.name,(u.has(s.name)?[...new Set(c)]:c).join(" ").trim())}for(const s of t.attributes.data){if(!r.has(s))continue;let c=r.get(s).split(p).filter(m=>!!m);const l=`data-${s}`;if(r.has(l)){if(!t.attributes.merge.has(l))throw new Error(`[${i}] Can not transform attribute to data-attribute, data-attribute already exists. [${s}]`);const m=r.get(l).split(p).filter(b=>!!b);if(t.xhtml&&!c.length&&!m.length)continue;c=[...m,...c]}r.set(l,(u.has(s)?[...new Set(c)]:c).join(" ").trim()),t.attributes.remove.has(s)||t.attributes.remove.add(s)}for(const s of t.attributes.remove)r.has(s)&&r.delete(s);return` !!s).map(s=>`${s}="${r.get(s)}"`).join(" ")}`:""}> ${o} `})},M=(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()),U(e.dataset.src||e.src).then(n=>{const a=J(n,e),r=R(a);B(e,r)}).catch(n=>console.error(`[${i}] ${n.toString()}`))},q=(e=null,n=null,a=null)=>{if(!e)throw new Error(`[${i}] Required argument is missing! [node]`);if(e.tagName!=="IMG")throw new Error(`[${i}] Required argument is not valid! [node]`);if(!a)throw new Error(`[${i}] Required argument is missing! [vnode]`);if(e[f]||(e[f]=new Set),e[f].has("processed"))return;e[f].add("processed");const r=_?a.dirs:a.data.directives;if(r.length>1)throw new Error(`[${i}] Node has more than 1 directive! [${_?"vnode.dirs":"vnode.data.directives"}]`);r[0].modifiers[t.directive.spriteModifierName]&&e[f].add("sprite"),!t._observer&&e.dataset.src&&(e.src=e.dataset.src,delete e.dataset.src),e.dataset.src?W().observe(e):M(e)};d.directive(t.directive.name,_?{beforeMount:q}:{bind:q})},be={install:pe};export{be as default}; //# sourceMappingURL=index-3d4ca26e.js.map