UNPKG

vite-awesome-svg-loader

Version:

A universal Vite SVG loader. Imports SVGs as source code, base64 and data URI. Preserves stroke width. Replaces colors with currentColor or custom colors. Creates SVG sprites. Optimizes SVGs.

3 lines (2 loc) 2.54 kB
"use strict";const r=require("../integration-utils/index-CyvitpnO.cjs"),s=require("../common-utils/index-Bp2I1MnI.cjs");class i{_src;_container;_svgEl;_useEl;_updateSrcRes={};constructor(t,e){this._svgEl=document.createElementNS("http://www.w3.org/2000/svg","svg"),this._useEl=document.createElementNS("http://www.w3.org/2000/svg","use"),this._svgEl.appendChild(this._useEl),this.setSrc(t),e&&this.mount(e)}mount(t){return this._container=s.f(this._svgEl,t),this}unmount(){return this._svgEl.parentElement?.removeChild(this._svgEl),this._container=void 0,r.T(this._updateSrcRes.id),this}setSvgElAttrs(t){return s.a(this._svgEl),s.u(this._svgEl,t),this._setRequiredSvgElAttrs(),this}_setRequiredSvgElAttrs(){return this._updateSrcRes.attrs&&s.u(this._svgEl,this._updateSrcRes.attrs),this}setUseElAttrs(t){return s.a(this._useEl),s.u(this._useEl,t),this._setRequiredUseElAttrs(),this}_setRequiredUseElAttrs(){return this._updateSrcRes.id&&s.u(this._useEl,{href:"#"+this._updateSrcRes.id}),this}setSrc(t){return this._updateSrcRes=r.z(this._src,t),this._src=t,this._setRequiredSvgElAttrs(),this._setRequiredUseElAttrs(),this}getSrc(){return this._src}getContainer(){return this._container}getSvgEl(){return this._svgEl}getUseEl(){return this._useEl}}class h extends i{_span;_size="";_color="";_colorTransition="";constructor(t,e){super(t),r.N(),this._span=document.createElement("span"),this._setWrapperClass(),this._span.appendChild(this._svgEl),this.setColorTransition(""),e&&this.mount(e)}mount(t){return this._container=s.f(this._span,t),this}unmount(){return this._span.parentElement?.removeChild(this._span),this._container=void 0,r.T(this._updateSrcRes.id),this}_setRequiredSvgElAttrs(){return super._setRequiredSvgElAttrs(),s.c(this._svgEl,"aria-hidden","true"),this}setWrapperAttrs(t){return s.a(this._span),s.u(this._span,t),this.setSize(this._size),this.setColor(this._color),this.setColorTransition(this._colorTransition),this._setWrapperClass(),this}_setWrapperClass(){this._span.classList.add("vite-awesome-svg-loader-icon")}getWrapper(){return this._span}setSize(t){return t||="",this._span.style.setProperty("--size",t),this._size=t,this}getSize(){return this._size}setColor(t){return t||="",this._span.style.setProperty("--color",t),this._color=t,this}getColor(){return this._color}setColorTransition(t){return t||=r.A,this._span.style.setProperty("--color-transition",t),this._colorTransition=t,this}getColorTransition(){return this._colorTransition}}exports.d=h;exports.u=i; //# sourceMappingURL=index-Hh8Z7qoP.cjs.map