UNPKG

@oslokommune/punkt-elements

Version:

Komponentbiblioteket til Punkt, et designsystem laget av Oslo Origo

89 lines (88 loc) 3.39 kB
import { E as f, T as v, P as m, x as y, n as h, a as P } from "./element-CgEWt74-.js"; import { e as g, i as k, t as _ } from "./directive-oAbCiebi.js"; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ class a extends k { constructor(t) { if (super(t), this.it = f, t.type !== _.CHILD) throw Error(this.constructor.directiveName + "() can only be used in child bindings"); } render(t) { if (t === f || t == null) return this._t = void 0, this.it = t; if (t === v) 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; const s = [t]; return s.raw = s, this._t = { _$litType$: this.constructor.resultType, strings: s, values: [] }; } } a.directiveName = "unsafeHTML", a.resultType = 1; const x = g(a); /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ class d extends a { } d.directiveName = "unsafeSVG", d.resultType = 2; const w = g(d); var I = Object.defineProperty, b = Object.getOwnPropertyDescriptor, n = (e, t, s, o) => { for (var i = o > 1 ? void 0 : o ? b(t, s) : t, p = e.length - 1, l; p >= 0; p--) (l = e[p]) && (i = (o ? l(t, s, i) : l(i)) || i); return o && i && I(t, s, i), i; }; window.pktFetch = window.pktFetch === void 0 ? fetch : window.pktFetch; window.pktIconPath = window.pktIconPath || "https://punkt-cdn.oslo.kommune.no/latest/icons/"; const C = (e) => new Promise((t) => setTimeout(t, e)), c = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"></svg>', u = {}, S = async (e, t) => { let s = 0; for (; u[t + e + ".svg"] === "fetching" && (s++, !(s > 50)); ) await C(50); return localStorage.getItem(t + e + ".svg") ? Promise.resolve(localStorage.getItem(t + e + ".svg")) : typeof window.pktFetch == "function" ? (u[t + e + ".svg"] = "fetching", Promise.resolve( window.pktFetch(t + e + ".svg").then((o) => o.ok ? o.text() : (console.error("Missing icon: " + t + e + ".svg"), c)).then((o) => (o !== c && localStorage.setItem(t + e + ".svg", o), u[t + e + ".svg"] = "fetched", o)) )) : Promise.resolve(c); }; let r = class extends m { constructor() { super(...arguments), this.path = window.pktIconPath, this.name = "", this.icon = w(c), this._updatedProps = []; } connectedCallback() { super.connectedCallback(), this.classList.add("pkt-icon"); } async attributeChangedCallback(e, t, s) { super.attributeChangedCallback(e, t, s), (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 = "") { this._updatedProps.length > 0 ? (this.path || (this.path, window.pktIconPath), this.icon = w( await S(this.name || "", this.path).then((t) => t) ), this._updatedProps = []) : this._updatedProps.includes(e) || this._updatedProps.push(e); } render() { return y`${this.name && this.icon}`; } }; n([ h({ type: String, reflect: !1 }) ], r.prototype, "path", 2); n([ h({ type: String, reflect: !0 }) ], r.prototype, "name", 2); n([ h({ type: SVGElement }) ], r.prototype, "icon", 2); n([ h({ type: Array, noAccessor: !0 }) ], r.prototype, "_updatedProps", 2); r = n([ P("pkt-icon") ], r); export { r as P, x as o };