UNPKG

@oslokommune/punkt-elements

Version:

Komponentbiblioteket til Punkt, et designsystem laget av Oslo Origo

1 lines 2.85 kB
const e=require(`./element-DjtxO-1r.cjs`),t=require(`./directive-CJ2giQBZ.cjs`);var n=class extends t.n{constructor(n){if(super(n),this.it=e.l,n.type!==t.r.CHILD)throw Error(this.constructor.directiveName+`() can only be used in child bindings`)}render(t){if(t===e.l||t==null)return this._t=void 0,this.it=t;if(t===e.u)return t;if(typeof t!=`string`)throw Error(this.constructor.directiveName+`() called with a non-string value`);if(t===this.it)return this._t;this.it=t;let n=[t];return n.raw=n,this._t={_$litType$:this.constructor.resultType,strings:n,values:[]}}};n.directiveName=`unsafeHTML`,n.resultType=1;var r=t.t(n),i=class extends n{};i.directiveName=`unsafeSVG`,i.resultType=2;var a=t.t(i),o=`https://punkt-cdn.oslo.kommune.no/latest/icons/`;typeof window<`u`&&(window.pktFetch=window.pktFetch===void 0?fetch:window.pktFetch,window.pktIconPath=window.pktIconPath||o);var s=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"></svg>`,c={},l=2,u=1500,d=typeof Storage<`u`&&typeof sessionStorage<`u`,f=e=>window.pktFetch(e).then(t=>{if(!t.ok)throw Error(`Missing icon: `+e);return t.text()}),p=async(e,t=l)=>{try{return await f(e)}catch{return t>0?(await new Promise(e=>setTimeout(e,u)),p(e,t-1)):(console.error(`Failed to fetch icon: `+e),s)}},m=async(e,t)=>{let n=t+e+`.svg`;return d&&sessionStorage.getItem(n)?sessionStorage.getItem(n):n in c?c[n]:typeof window<`u`&&typeof window.pktFetch==`function`?(c[n]=p(n).then(e=>(e!==s&&d&&sessionStorage.setItem(n,e),delete c[n],e)),c[n]):s},h=class extends e.t{constructor(...e){super(...e),this.path=typeof window<`u`?window.pktIconPath:o,this.name=``,this.icon=a(s),this._updatedProps=[]}connectedCallback(){super.connectedCallback(),this.classList.add(`pkt-icon`)}async attributeChangedCallback(e,t,n){super.attributeChangedCallback(e,t,n),(e===`name`||e===`path`)&&this.getIcon(this.name)}async updated(e){super.updated(e),(e.has(`name`)||e.has(`path`))&&this.getIcon(this.name)}async getIcon(e=``){if(this._updatedProps.length>0){this.path||=typeof window<`u`?window.pktIconPath:o;try{this.icon=a(await m(this.name||``,this.path))}catch{this.icon=a(s)}this._updatedProps=[]}else this._updatedProps.includes(e)||this._updatedProps.push(e)}render(){return e.d`${this.name&&this.icon}`}};e.r([e.s({type:String,reflect:!1})],h.prototype,`path`,void 0),e.r([e.s({type:String,reflect:!0})],h.prototype,`name`,void 0),e.r([e.s({type:SVGElement})],h.prototype,`icon`,void 0),e.r([e.s({type:Array,noAccessor:!0})],h.prototype,`_updatedProps`,void 0);try{e.c(`pkt-icon`)(h)}catch{console.warn(`Forsøker å definere <pkt-icon>, men den er allerede definert`)}var g=h;Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return g}});