nve-designsystem 1.4.6 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,9 @@ const a = t`
13
13
  position: relative;
14
14
  border: none;
15
15
  min-width: 48px;
16
- transition: background-color 0.3s ease;
16
+ transition:
17
+ background-color 0.3s ease,
18
+ border-color 0.3s ease;
17
19
  }
18
20
 
19
21
  :host([has-icon-only])::part(base) {
@@ -1,10 +1,12 @@
1
1
  import { LitElement } from 'lit';
2
2
  /**
3
3
  * Et ikon.
4
- * Vi bruker ikoner fra Material Symbols.
5
- * Vi bruker strek-tykkelse 400 uansett størrelse ikonet.
6
- * Fill skal ikke brukes.
4
+ * Vi bruker ikoner fra Material Symbols, men det er også mulig å bruke ikoner fra egen repo. Det anbefales sterkt å bruke Material-ikonene.
5
+ * Strektykkelsen skal være 400, uavhengig av ikonets størrelse, og kun stilene Sharp og Outlined skal brukes.
6
+ * Fill-stilen bør unngås, da den fyller hele ikonet med farge i stedet for å bruke kun konturer
7
7
  * @see https://fonts.google.com/icons
8
+ * @csspart icon - Selve ikon span-element.
9
+ * @cssproperty --icon-size - Størrelse på ikonet. 16px er standard.
8
10
  */
9
11
  export default class NveIcon extends LitElement {
10
12
  static styles: import('lit').CSSResult[];
@@ -12,6 +14,8 @@ export default class NveIcon extends LitElement {
12
14
  library: 'Outlined' | 'Sharp';
13
15
  /** Navnet på ikonet i Material Symbols-biblioteket */
14
16
  name: string;
17
+ src: string;
18
+ alt: string | undefined;
15
19
  /** Boolean som angir om ikonet har hatt tid til å laste. */
16
20
  private iconLoaded;
17
21
  protected firstUpdated(): void;
@@ -1,148 +1,164 @@
1
- import { r as U, x as z } from "../../chunks/lit-element.js";
2
- import { n as q, t as H } from "../../chunks/property.js";
1
+ import { r as U, x as F } from "../../chunks/lit-element.js";
2
+ import { n as j, t as H } from "../../chunks/property.js";
3
3
  import { r as J } from "../../chunks/state.js";
4
4
  import K from "./nve-icon.styles.js";
5
- function Q(s) {
5
+ import { e as Q } from "../../chunks/class-map.js";
6
+ import { o as V } from "../../chunks/if-defined.js";
7
+ function X(s) {
6
8
  return s && s.__esModule && Object.prototype.hasOwnProperty.call(s, "default") ? s.default : s;
7
9
  }
8
- var F = { exports: {} }, k;
9
- function V() {
10
- return k || (k = 1, function(s) {
10
+ var I = { exports: {} }, q;
11
+ function Y() {
12
+ return q || (q = 1, function(s) {
11
13
  (function() {
12
14
  function i(e, n) {
13
15
  document.addEventListener ? e.addEventListener("scroll", n, !1) : e.attachEvent("scroll", n);
14
16
  }
15
- function L(e) {
17
+ function T(e) {
16
18
  document.body ? e() : document.addEventListener ? document.addEventListener("DOMContentLoaded", function n() {
17
19
  document.removeEventListener("DOMContentLoaded", n), e();
18
20
  }) : document.attachEvent("onreadystatechange", function n() {
19
21
  (document.readyState == "interactive" || document.readyState == "complete") && (document.detachEvent("onreadystatechange", n), e());
20
22
  });
21
23
  }
22
- function u(e) {
24
+ function p(e) {
23
25
  this.g = document.createElement("div"), this.g.setAttribute("aria-hidden", "true"), this.g.appendChild(document.createTextNode(e)), this.h = document.createElement("span"), this.i = document.createElement("span"), this.m = document.createElement("span"), this.j = document.createElement("span"), this.l = -1, this.h.style.cssText = "max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;", this.i.style.cssText = "max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;", this.j.style.cssText = "max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;", this.m.style.cssText = "display:inline-block;width:200%;height:200%;font-size:16px;max-width:none;", this.h.appendChild(this.m), this.i.appendChild(this.j), this.g.appendChild(this.h), this.g.appendChild(this.i);
24
26
  }
25
27
  function r(e, n) {
26
28
  e.g.style.cssText = "max-width:none;min-width:20px;min-height:20px;display:inline-block;overflow:hidden;position:absolute;width:auto;margin:0;padding:0;top:-999px;white-space:nowrap;font-synthesis:none;font:" + n + ";";
27
29
  }
28
- function x(e) {
30
+ function E(e) {
29
31
  var n = e.g.offsetWidth, t = n + 100;
30
32
  return e.j.style.width = t + "px", e.i.scrollLeft = t, e.h.scrollLeft = e.h.scrollWidth + 100, e.l !== n ? (e.l = n, !0) : !1;
31
33
  }
32
- function v(e, n) {
34
+ function y(e, n) {
33
35
  function t() {
34
- var l = p;
35
- x(l) && l.g.parentNode !== null && n(l.l);
36
+ var a = u;
37
+ E(a) && a.g.parentNode !== null && n(a.l);
36
38
  }
37
- var p = e;
38
- i(e.h, t), i(e.i, t), x(e);
39
+ var u = e;
40
+ i(e.h, t), i(e.i, t), E(e);
39
41
  }
40
- function I(e, n, t) {
42
+ function N(e, n, t) {
41
43
  n = n || {}, t = t || window, this.family = e, this.style = n.style || "normal", this.weight = n.weight || "normal", this.stretch = n.stretch || "normal", this.context = t;
42
44
  }
43
- var O = null, T = null, P = null, A = null;
45
+ var P = null, _ = null, $ = null, A = null;
44
46
  function B(e) {
45
- return T === null && (N(e) && /Apple/.test(window.navigator.vendor) ? (e = /AppleWebKit\/([0-9]+)(?:\.([0-9]+))(?:\.([0-9]+))/.exec(window.navigator.userAgent), T = !!e && 603 > parseInt(e[1], 10)) : T = !1), T;
47
+ return _ === null && (S(e) && /Apple/.test(window.navigator.vendor) ? (e = /AppleWebKit\/([0-9]+)(?:\.([0-9]+))(?:\.([0-9]+))/.exec(window.navigator.userAgent), _ = !!e && 603 > parseInt(e[1], 10)) : _ = !1), _;
46
48
  }
47
- function N(e) {
49
+ function S(e) {
48
50
  return A === null && (A = !!e.document.fonts), A;
49
51
  }
50
- function y(e, n) {
51
- var t = e.style, p = e.weight;
52
- if (P === null) {
53
- var l = document.createElement("div");
52
+ function g(e, n) {
53
+ var t = e.style, u = e.weight;
54
+ if ($ === null) {
55
+ var a = document.createElement("div");
54
56
  try {
55
- l.style.font = "condensed 100px sans-serif";
57
+ a.style.font = "condensed 100px sans-serif";
56
58
  } catch {
57
59
  }
58
- P = l.style.font !== "";
60
+ $ = a.style.font !== "";
59
61
  }
60
- return [t, p, P ? e.stretch : "", "100px", n].join(" ");
62
+ return [t, u, $ ? e.stretch : "", "100px", n].join(" ");
61
63
  }
62
- I.prototype.load = function(e, n) {
63
- var t = this, p = e || "BESbswy", l = 0, g = n || 3e3, S = (/* @__PURE__ */ new Date()).getTime();
64
- return new Promise(function(M, $) {
65
- if (N(t.context) && !B(t.context)) {
66
- var G = new Promise(function(w, b) {
64
+ N.prototype.load = function(e, n) {
65
+ var t = this, u = e || "BESbswy", a = 0, w = n || 3e3, z = (/* @__PURE__ */ new Date()).getTime();
66
+ return new Promise(function(M, k) {
67
+ if (S(t.context) && !B(t.context)) {
68
+ var G = new Promise(function(b, x) {
67
69
  function d() {
68
- (/* @__PURE__ */ new Date()).getTime() - S >= g ? b(Error("" + g + "ms timeout exceeded")) : t.context.document.fonts.load(y(t, '"' + t.family + '"'), p).then(function(m) {
69
- 1 <= m.length ? w() : setTimeout(d, 25);
70
- }, b);
70
+ (/* @__PURE__ */ new Date()).getTime() - z >= w ? x(Error("" + w + "ms timeout exceeded")) : t.context.document.fonts.load(g(t, '"' + t.family + '"'), u).then(function(m) {
71
+ 1 <= m.length ? b() : setTimeout(d, 25);
72
+ }, x);
71
73
  }
72
74
  d();
73
- }), R = new Promise(function(w, b) {
74
- l = setTimeout(function() {
75
- b(Error("" + g + "ms timeout exceeded"));
76
- }, g);
75
+ }), R = new Promise(function(b, x) {
76
+ a = setTimeout(function() {
77
+ x(Error("" + w + "ms timeout exceeded"));
78
+ }, w);
77
79
  });
78
80
  Promise.race([R, G]).then(function() {
79
- clearTimeout(l), M(t);
80
- }, $);
81
- } else L(function() {
82
- function w() {
81
+ clearTimeout(a), M(t);
82
+ }, k);
83
+ } else T(function() {
84
+ function b() {
83
85
  var o;
84
- (o = c != -1 && h != -1 || c != -1 && f != -1 || h != -1 && f != -1) && ((o = c != h && c != f && h != f) || (O === null && (o = /AppleWebKit\/([0-9]+)(?:\.([0-9]+))/.exec(window.navigator.userAgent), O = !!o && (536 > parseInt(o[1], 10) || parseInt(o[1], 10) === 536 && 11 >= parseInt(o[2], 10))), o = O && (c == _ && h == _ && f == _ || c == D && h == D && f == D || c == W && h == W && f == W)), o = !o), o && (a.parentNode !== null && a.parentNode.removeChild(a), clearTimeout(l), M(t));
86
+ (o = c != -1 && h != -1 || c != -1 && f != -1 || h != -1 && f != -1) && ((o = c != h && c != f && h != f) || (P === null && (o = /AppleWebKit\/([0-9]+)(?:\.([0-9]+))/.exec(window.navigator.userAgent), P = !!o && (536 > parseInt(o[1], 10) || parseInt(o[1], 10) === 536 && 11 >= parseInt(o[2], 10))), o = P && (c == D && h == D && f == D || c == O && h == O && f == O || c == W && h == W && f == W)), o = !o), o && (l.parentNode !== null && l.parentNode.removeChild(l), clearTimeout(a), M(t));
85
87
  }
86
- function b() {
87
- if ((/* @__PURE__ */ new Date()).getTime() - S >= g) a.parentNode !== null && a.parentNode.removeChild(a), $(Error("" + g + "ms timeout exceeded"));
88
+ function x() {
89
+ if ((/* @__PURE__ */ new Date()).getTime() - z >= w) l.parentNode !== null && l.parentNode.removeChild(l), k(Error("" + w + "ms timeout exceeded"));
88
90
  else {
89
91
  var o = t.context.document.hidden;
90
- (o === !0 || o === void 0) && (c = d.g.offsetWidth, h = m.g.offsetWidth, f = E.g.offsetWidth, w()), l = setTimeout(b, 50);
92
+ (o === !0 || o === void 0) && (c = d.g.offsetWidth, h = m.g.offsetWidth, f = C.g.offsetWidth, b()), a = setTimeout(x, 50);
91
93
  }
92
94
  }
93
- var d = new u(p), m = new u(p), E = new u(p), c = -1, h = -1, f = -1, _ = -1, D = -1, W = -1, a = document.createElement("div");
94
- a.dir = "ltr", r(d, y(t, "sans-serif")), r(m, y(t, "serif")), r(E, y(t, "monospace")), a.appendChild(d.g), a.appendChild(m.g), a.appendChild(E.g), t.context.document.body.appendChild(a), _ = d.g.offsetWidth, D = m.g.offsetWidth, W = E.g.offsetWidth, b(), v(d, function(o) {
95
- c = o, w();
96
- }), r(d, y(t, '"' + t.family + '",sans-serif')), v(m, function(o) {
97
- h = o, w();
98
- }), r(m, y(t, '"' + t.family + '",serif')), v(E, function(o) {
99
- f = o, w();
100
- }), r(E, y(t, '"' + t.family + '",monospace'));
95
+ var d = new p(u), m = new p(u), C = new p(u), c = -1, h = -1, f = -1, D = -1, O = -1, W = -1, l = document.createElement("div");
96
+ l.dir = "ltr", r(d, g(t, "sans-serif")), r(m, g(t, "serif")), r(C, g(t, "monospace")), l.appendChild(d.g), l.appendChild(m.g), l.appendChild(C.g), t.context.document.body.appendChild(l), D = d.g.offsetWidth, O = m.g.offsetWidth, W = C.g.offsetWidth, x(), y(d, function(o) {
97
+ c = o, b();
98
+ }), r(d, g(t, '"' + t.family + '",sans-serif')), y(m, function(o) {
99
+ h = o, b();
100
+ }), r(m, g(t, '"' + t.family + '",serif')), y(C, function(o) {
101
+ f = o, b();
102
+ }), r(C, g(t, '"' + t.family + '",monospace'));
101
103
  });
102
104
  });
103
- }, s.exports = I;
105
+ }, s.exports = N;
104
106
  })();
105
- }(F)), F.exports;
107
+ }(I)), I.exports;
106
108
  }
107
- var X = V();
108
- const Y = /* @__PURE__ */ Q(X);
109
- var Z = Object.defineProperty, ee = Object.getOwnPropertyDescriptor, j = (s, i, L, u) => {
110
- for (var r = u > 1 ? void 0 : u ? ee(i, L) : i, x = s.length - 1, v; x >= 0; x--)
111
- (v = s[x]) && (r = (u ? v(i, L, r) : v(r)) || r);
112
- return u && r && Z(i, L, r), r;
109
+ var Z = Y();
110
+ const ee = /* @__PURE__ */ X(Z);
111
+ var te = Object.defineProperty, ne = Object.getOwnPropertyDescriptor, L = (s, i, T, p) => {
112
+ for (var r = p > 1 ? void 0 : p ? ne(i, T) : i, E = s.length - 1, y; E >= 0; E--)
113
+ (y = s[E]) && (r = (p ? y(i, T, r) : y(r)) || r);
114
+ return p && r && te(i, T, r), r;
113
115
  };
114
- let C = class extends U {
116
+ let v = class extends U {
115
117
  constructor() {
116
- super(...arguments), this.library = "Sharp", this.name = "", this.iconLoaded = !1;
118
+ super(...arguments), this.library = "Sharp", this.name = "", this.src = "", this.alt = void 0, this.iconLoaded = !1;
117
119
  }
118
120
  firstUpdated() {
121
+ if (this.src) return;
119
122
  if (!document.getElementById(`material-icons-${this.library.toLowerCase()}`)) {
120
123
  const i = document.createElement("link");
121
124
  i.id = `material-icons-${this.library.toLowerCase()}`, i.rel = "stylesheet", i.href = `https://fonts.googleapis.com/css2?family=Material+Symbols+${this.library}:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200`, document.head.appendChild(i);
122
125
  }
123
- new Y(`Material Symbols ${this.library}`).load().then(() => {
126
+ new ee(`Material Symbols ${this.library}`).load().then(() => {
124
127
  this.iconLoaded = !0, this.requestUpdate();
125
128
  }).catch((i) => {
126
129
  console.error("Failed to load the icon font:", i);
127
130
  });
128
131
  }
129
132
  render() {
130
- return this.iconLoaded ? z`<span part="icon" style="font-family: 'Material Symbols ${this.library}'; ">${this.name}</span>` : z`<nve-skeleton class="placeholder" effect="sheen"></nve-skeleton>`;
133
+ return this.src ? F`<img src=${this.src} alt=${V(this.alt)} />` : !this.src && this.iconLoaded ? F`<span
134
+ part="icon"
135
+ class=${Q({
136
+ "material-outlined": this.library === "Outlined",
137
+ "material-sharp": this.library === "Sharp"
138
+ })}
139
+ >${this.name}</span
140
+ >` : F`<nve-skeleton class="placeholder" effect="sheen"></nve-skeleton>`;
131
141
  }
132
142
  };
133
- C.styles = [K];
134
- j([
135
- q({ type: String })
136
- ], C.prototype, "library", 2);
137
- j([
138
- q({ reflect: !0 })
139
- ], C.prototype, "name", 2);
140
- j([
143
+ v.styles = [K];
144
+ L([
145
+ j()
146
+ ], v.prototype, "library", 2);
147
+ L([
148
+ j({ type: String, reflect: !0 })
149
+ ], v.prototype, "name", 2);
150
+ L([
151
+ j()
152
+ ], v.prototype, "src", 2);
153
+ L([
154
+ j()
155
+ ], v.prototype, "alt", 2);
156
+ L([
141
157
  J()
142
- ], C.prototype, "iconLoaded", 2);
143
- C = j([
158
+ ], v.prototype, "iconLoaded", 2);
159
+ v = L([
144
160
  H("nve-icon")
145
- ], C);
161
+ ], v);
146
162
  export {
147
- C as default
163
+ v as default
148
164
  };
@@ -8,30 +8,41 @@ const n = e`
8
8
 
9
9
  /* prevent icon beeing highlighted */
10
10
  :host {
11
+ display: flex;
12
+ user-select: none; /* Non-prefixed version, currently supported by Chrome, Edge, Opera and Firefox */
11
13
  -webkit-touch-callout: none; /* iOS Safari */
12
14
  -webkit-user-select: none; /* Safari */
13
- -khtml-user-select: none; /* Konqueror HTML */
14
- -moz-user-select: none; /* Old versions of Firefox */
15
- -ms-user-select: none; /* Internet Explorer/Edge */
16
- user-select: none; /* Non-prefixed version, currently
17
- supported by Chrome, Edge, Opera and Firefox */
15
+ --icon-size: 16px;
16
+ font-size: var(--icon-size);
17
+ line-height: var(--icon-size);
18
18
  }
19
- :host {
20
- display: flex;
19
+
20
+ :is(img) {
21
+ width: var(--icon-size);
22
+ height: var(--icon-size);
21
23
  }
22
24
 
23
25
  /* we need it to center the icon */
24
26
  :is(span) {
25
27
  display: inline-flex;
26
- line-height: 24px;
28
+ font-size: inherit;
29
+ line-height: inherit;
27
30
  font-weight: var(--font-weight-regular);
28
31
  }
29
32
 
30
33
  .placeholder::part(indicator) {
31
- width: 24px;
32
- height: 24px;
34
+ width: var(--icon-size);
35
+ height: var(--icon-size);
33
36
  border-radius: 4px;
34
37
  }
38
+
39
+ .material-outlined {
40
+ font-family: 'Material Symbols Outlined';
41
+ }
42
+
43
+ .material-sharp {
44
+ font-family: 'Material Symbols Sharp';
45
+ }
35
46
  `;
36
47
  export {
37
48
  n as default