@postnord/web-components
Version:
PostNord Web Components
5 lines • 1.33 kB
JavaScript
/*!
* Built with Stencil
* By PostNord.
*/
import{t,r as i,g as s,h,a as e}from"./p-CAEP792y.js";const n=class{constructor(t){i(this,t)}get hostElement(){return s(this)}illustration;width;height;fill=!1;handleFill(){this.fill&&(this.width="100%",this.height="100%")}componentWillRender(){if(this.handleFill(),this.width||this.height)return this.setSizes();this.getSizeFromSvg()}componentDidRender(){this.hostElement.querySelector("svg")?.setAttribute("width",this.width),this.hostElement.querySelector("svg")?.setAttribute("height",this.height)}getSizeFromSvg(){const t=this.illustration?.match(/<svg[^>]*?viewBox=(["\'])?((?:.(?!\1|>))*.?)\1?/)?.[2];if(!t)return;const[,,i="",s=""]=t?.split(" ")||[];i&&s&&(this.width=`${Number(i)}px`,this.height=`${Number(s)}px`,this.setSizes())}setSizes(){this.hostElement.style.setProperty("--pn-width",this.width),this.hostElement.style.setProperty("--pn-height",this.height)}render(){return h(e,{key:"3f2e44ec10a5a2fc9fd9a69f94963ab4e79fb877",role:"presentation",innerHTML:this.illustration,"data-fill":this.fill})}static get watchers(){return{fill:[{handleFill:0}]}}};n.style=`${t("pn-illustration")}{display:inline-block}${t("pn-illustration")}[data-fill]{display:block}${t("pn-illustration")}>svg{width:var(--pn-width);height:var(--pn-height);display:block}`;export{n as pn_illustration}