@wral/active-alerts 0.1.4 → 0.2.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.
package/dist/define.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright 2019 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
5
|
*/
|
|
6
|
-
const H = globalThis,
|
|
6
|
+
const H = globalThis, z = H.ShadowRoot && (H.ShadyCSS === void 0 || H.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype, j = Symbol(), V = /* @__PURE__ */ new WeakMap();
|
|
7
7
|
let tt = class {
|
|
8
8
|
constructor(t, e, s) {
|
|
9
9
|
if (this._$cssResult$ = !0, s !== j) throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");
|
|
@@ -12,7 +12,7 @@ let tt = class {
|
|
|
12
12
|
get styleSheet() {
|
|
13
13
|
let t = this.o;
|
|
14
14
|
const e = this.t;
|
|
15
|
-
if (
|
|
15
|
+
if (z && t === void 0) {
|
|
16
16
|
const s = e !== void 0 && e.length === 1;
|
|
17
17
|
s && (t = V.get(e)), t === void 0 && ((this.o = t = new CSSStyleSheet()).replaceSync(this.cssText), s && V.set(e, t));
|
|
18
18
|
}
|
|
@@ -30,12 +30,12 @@ const at = (i) => new tt(typeof i == "string" ? i : i + "", void 0, j), lt = (i,
|
|
|
30
30
|
})(r) + i[n + 1]), i[0]);
|
|
31
31
|
return new tt(e, i, j);
|
|
32
32
|
}, ht = (i, t) => {
|
|
33
|
-
if (
|
|
33
|
+
if (z) i.adoptedStyleSheets = t.map(((e) => e instanceof CSSStyleSheet ? e : e.styleSheet));
|
|
34
34
|
else for (const e of t) {
|
|
35
35
|
const s = document.createElement("style"), r = H.litNonce;
|
|
36
36
|
r !== void 0 && s.setAttribute("nonce", r), s.textContent = e.cssText, i.appendChild(s);
|
|
37
37
|
}
|
|
38
|
-
}, q =
|
|
38
|
+
}, q = z ? (i) => i : (i) => i instanceof CSSStyleSheet ? ((t) => {
|
|
39
39
|
let e = "";
|
|
40
40
|
for (const s of t.cssRules) e += s.cssText;
|
|
41
41
|
return at(e);
|
|
@@ -45,7 +45,7 @@ const at = (i) => new tt(typeof i == "string" ? i : i + "", void 0, j), lt = (i,
|
|
|
45
45
|
* Copyright 2017 Google LLC
|
|
46
46
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
47
47
|
*/
|
|
48
|
-
const { is: ct, defineProperty: dt, getOwnPropertyDescriptor: pt, getOwnPropertyNames: ut, getOwnPropertySymbols: ft, getPrototypeOf: $t } = Object, M = globalThis, F = M.trustedTypes, mt = F ? F.emptyScript : "", gt = M.reactiveElementPolyfillSupport, x = (i, t) => i,
|
|
48
|
+
const { is: ct, defineProperty: dt, getOwnPropertyDescriptor: pt, getOwnPropertyNames: ut, getOwnPropertySymbols: ft, getPrototypeOf: $t } = Object, M = globalThis, F = M.trustedTypes, mt = F ? F.emptyScript : "", gt = M.reactiveElementPolyfillSupport, x = (i, t) => i, L = { toAttribute(i, t) {
|
|
49
49
|
switch (t) {
|
|
50
50
|
case Boolean:
|
|
51
51
|
i = i ? mt : null;
|
|
@@ -73,7 +73,7 @@ const { is: ct, defineProperty: dt, getOwnPropertyDescriptor: pt, getOwnProperty
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
return e;
|
|
76
|
-
} }, et = (i, t) => !ct(i, t), K = { attribute: !0, type: String, converter:
|
|
76
|
+
} }, et = (i, t) => !ct(i, t), K = { attribute: !0, type: String, converter: L, reflect: !1, useDefault: !1, hasChanged: et };
|
|
77
77
|
Symbol.metadata ??= Symbol("metadata"), M.litPropertyMetadata ??= /* @__PURE__ */ new WeakMap();
|
|
78
78
|
let b = class extends HTMLElement {
|
|
79
79
|
static addInitializer(t) {
|
|
@@ -172,14 +172,14 @@ let b = class extends HTMLElement {
|
|
|
172
172
|
_$ET(t, e) {
|
|
173
173
|
const s = this.constructor.elementProperties.get(t), r = this.constructor._$Eu(t, s);
|
|
174
174
|
if (r !== void 0 && s.reflect === !0) {
|
|
175
|
-
const n = (s.converter?.toAttribute !== void 0 ? s.converter :
|
|
175
|
+
const n = (s.converter?.toAttribute !== void 0 ? s.converter : L).toAttribute(e, s.type);
|
|
176
176
|
this._$Em = t, n == null ? this.removeAttribute(r) : this.setAttribute(r, n), this._$Em = null;
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
_$AK(t, e) {
|
|
180
180
|
const s = this.constructor, r = s._$Eh.get(t);
|
|
181
181
|
if (r !== void 0 && this._$Em !== r) {
|
|
182
|
-
const n = s.getPropertyOptions(r), o = typeof n.converter == "function" ? { fromAttribute: n.converter } : n.converter?.fromAttribute !== void 0 ? n.converter :
|
|
182
|
+
const n = s.getPropertyOptions(r), o = typeof n.converter == "function" ? { fromAttribute: n.converter } : n.converter?.fromAttribute !== void 0 ? n.converter : L;
|
|
183
183
|
this._$Em = r;
|
|
184
184
|
const c = o.fromAttribute(e, n.type);
|
|
185
185
|
this[r] = c ?? this._$Ej?.get(r) ?? c, this._$Em = null;
|
|
@@ -581,21 +581,23 @@ async function v(i, t, e) {
|
|
|
581
581
|
const d = await a.json();
|
|
582
582
|
return d.caption && console.warn("Alert API provided a value with a caption field. The caption field is deprecated and will be removed."), (d?.items || []).some((l) => l.caption) && console.warn("Alert API provided an item with a caption field. The caption field is deprecated and will be removed."), d;
|
|
583
583
|
}
|
|
584
|
-
const Rt =
|
|
584
|
+
const Rt = {
|
|
585
|
+
lg: 1366
|
|
586
|
+
}, Lt = "https://api.wral.com/alerts/v1/active/alerts", zt = "https://assets.wral.com/a1cc0e86-adab-48e9-bd80-703cd2c56aff?w=1200&h=630", jt = (i) => String(i || "Alert").replace(/[^\p{L}\p{N}]/gu, " ").replace(/\s+/g, " ").trim() || "Alert", Dt = (i) => {
|
|
585
587
|
if (!i) return null;
|
|
586
588
|
const t = i.url || i.href || "", e = i.title || i.headline || "";
|
|
587
589
|
if (!t || !e) return null;
|
|
588
|
-
const s = i.topic || "", r = i.caption || s || "Alert",
|
|
590
|
+
const s = String(i.topic || "").trim(), r = s.toLowerCase(), n = i.caption || s || "Alert", o = i.image || i.imageUrl || i.image_url || zt;
|
|
589
591
|
return {
|
|
590
592
|
url: t,
|
|
591
593
|
title: e,
|
|
592
|
-
topic: s,
|
|
593
|
-
caption:
|
|
594
|
-
image:
|
|
594
|
+
topic: r || s,
|
|
595
|
+
caption: n,
|
|
596
|
+
image: o,
|
|
595
597
|
body: i.body || i.summary || "",
|
|
596
598
|
effectiveFrom: i.effectiveFrom || i.effective_from || ""
|
|
597
599
|
};
|
|
598
|
-
},
|
|
600
|
+
}, Bt = (i) => {
|
|
599
601
|
if (!i) return "";
|
|
600
602
|
try {
|
|
601
603
|
const t = new Date(i);
|
|
@@ -618,7 +620,7 @@ class ot extends C {
|
|
|
618
620
|
refreshInterval: { type: Number, attribute: "refresh-interval" }
|
|
619
621
|
};
|
|
620
622
|
constructor() {
|
|
621
|
-
super(), this.api =
|
|
623
|
+
super(), this.api = Lt, this.items = [], this.loading = !1, this.error = "", this.refreshInterval = 0, this._refreshId = null;
|
|
622
624
|
}
|
|
623
625
|
static styles = lt`
|
|
624
626
|
:host {
|
|
@@ -627,7 +629,7 @@ class ot extends C {
|
|
|
627
629
|
color: #000b27;
|
|
628
630
|
}
|
|
629
631
|
.wrapper {
|
|
630
|
-
max-width:
|
|
632
|
+
max-width: ${Rt.lg}px;
|
|
631
633
|
margin: 0 auto;
|
|
632
634
|
padding: 1rem 1.25rem 1.5rem;
|
|
633
635
|
}
|
|
@@ -700,10 +702,10 @@ class ot extends C {
|
|
|
700
702
|
color: #fff;
|
|
701
703
|
font-size: .75rem;
|
|
702
704
|
font-weight: 700;
|
|
703
|
-
padding: 0.125rem 0.
|
|
704
|
-
border-radius:
|
|
705
|
+
padding: 0.125rem 0.1875rem 0.05rem;
|
|
706
|
+
border-radius: 4px;
|
|
705
707
|
text-transform: uppercase;
|
|
706
|
-
background-color: #
|
|
708
|
+
background-color: #daa520; /* default (gold) */
|
|
707
709
|
letter-spacing: .03em;
|
|
708
710
|
}
|
|
709
711
|
.label.recommended-story {
|
|
@@ -780,7 +782,7 @@ class ot extends C {
|
|
|
780
782
|
this.loading = !0, this.error = "";
|
|
781
783
|
try {
|
|
782
784
|
const t = await this.fetchActiveAlerts();
|
|
783
|
-
this.items = (t?.items || []).map(
|
|
785
|
+
this.items = (t?.items || []).map(Dt).filter(Boolean);
|
|
784
786
|
} catch (t) {
|
|
785
787
|
console.error("[wral-active-alerts]", t), this.items = [], this.error = "Unable to load active alerts.";
|
|
786
788
|
} finally {
|
|
@@ -798,7 +800,7 @@ class ot extends C {
|
|
|
798
800
|
}
|
|
799
801
|
render() {
|
|
800
802
|
const { items: t, loading: e, error: s } = this, r = (n, o) => {
|
|
801
|
-
const c =
|
|
803
|
+
const c = Bt(n.effectiveFrom), a = String(n.topic || "").trim().toLowerCase();
|
|
802
804
|
return $`
|
|
803
805
|
<li class="alert" data-index=${o} aria-label="Site Alert">
|
|
804
806
|
<div class="thumb">
|
|
@@ -810,8 +812,8 @@ class ot extends C {
|
|
|
810
812
|
</div>
|
|
811
813
|
<div class="alert-body">
|
|
812
814
|
<div class="alert-header">
|
|
813
|
-
<div class="label ${
|
|
814
|
-
${
|
|
815
|
+
<div class="label ${a}">
|
|
816
|
+
${jt(n.caption)}
|
|
815
817
|
</div>
|
|
816
818
|
${c ? $`
|
|
817
819
|
<span class="date">
|
|
@@ -847,11 +849,11 @@ class ot extends C {
|
|
|
847
849
|
}
|
|
848
850
|
}
|
|
849
851
|
globalThis?.customElements && !globalThis.customElements.get("wral-active-alerts") && globalThis.customElements.define("wral-active-alerts", ot);
|
|
850
|
-
function
|
|
852
|
+
function Wt() {
|
|
851
853
|
const i = globalThis?.customElements;
|
|
852
854
|
i && (i.get("wral-active-alerts") || i.define("wral-active-alerts", ot));
|
|
853
855
|
}
|
|
854
|
-
typeof window < "u" && globalThis.customElements &&
|
|
856
|
+
typeof window < "u" && globalThis.customElements && Wt();
|
|
855
857
|
export {
|
|
856
|
-
|
|
858
|
+
Wt as defineAll
|
|
857
859
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import { LitElement as
|
|
2
|
-
import { createClient as
|
|
3
|
-
const
|
|
1
|
+
import { LitElement as d, css as m, html as i } from "lit";
|
|
2
|
+
import { createClient as f } from "@wral/sdk-alerts/v1";
|
|
3
|
+
const p = {
|
|
4
|
+
lg: 1366
|
|
5
|
+
}, h = "https://api.wral.com/alerts/v1/active/alerts", g = "https://assets.wral.com/a1cc0e86-adab-48e9-bd80-703cd2c56aff?w=1200&h=630", u = (t) => String(t || "Alert").replace(/[^\p{L}\p{N}]/gu, " ").replace(/\s+/g, " ").trim() || "Alert", b = (t) => {
|
|
4
6
|
if (!t) return null;
|
|
5
7
|
const e = t.url || t.href || "", s = t.title || t.headline || "";
|
|
6
8
|
if (!e || !s) return null;
|
|
7
|
-
const a = t.topic || "", l = t.caption || a || "Alert",
|
|
9
|
+
const a = String(t.topic || "").trim(), l = a.toLowerCase(), r = t.caption || a || "Alert", n = t.image || t.imageUrl || t.image_url || g;
|
|
8
10
|
return {
|
|
9
11
|
url: e,
|
|
10
12
|
title: s,
|
|
11
|
-
topic: a,
|
|
12
|
-
caption:
|
|
13
|
-
image:
|
|
13
|
+
topic: l || a,
|
|
14
|
+
caption: r,
|
|
15
|
+
image: n,
|
|
14
16
|
body: t.body || t.summary || "",
|
|
15
17
|
effectiveFrom: t.effectiveFrom || t.effective_from || ""
|
|
16
18
|
};
|
|
17
|
-
},
|
|
19
|
+
}, v = (t) => {
|
|
18
20
|
if (!t) return "";
|
|
19
21
|
try {
|
|
20
22
|
const e = new Date(t);
|
|
@@ -28,7 +30,7 @@ const f = "https://api.wral.com/alerts/v1/active/alerts", p = "https://assets.wr
|
|
|
28
30
|
return "";
|
|
29
31
|
}
|
|
30
32
|
};
|
|
31
|
-
class
|
|
33
|
+
class y extends d {
|
|
32
34
|
static properties = {
|
|
33
35
|
api: { type: String },
|
|
34
36
|
items: { state: !0 },
|
|
@@ -37,16 +39,16 @@ class b extends c {
|
|
|
37
39
|
refreshInterval: { type: Number, attribute: "refresh-interval" }
|
|
38
40
|
};
|
|
39
41
|
constructor() {
|
|
40
|
-
super(), this.api =
|
|
42
|
+
super(), this.api = h, this.items = [], this.loading = !1, this.error = "", this.refreshInterval = 0, this._refreshId = null;
|
|
41
43
|
}
|
|
42
|
-
static styles =
|
|
44
|
+
static styles = m`
|
|
43
45
|
:host {
|
|
44
46
|
display: block;
|
|
45
47
|
background: #f7f5f4;
|
|
46
48
|
color: #000b27;
|
|
47
49
|
}
|
|
48
50
|
.wrapper {
|
|
49
|
-
max-width:
|
|
51
|
+
max-width: ${p.lg}px;
|
|
50
52
|
margin: 0 auto;
|
|
51
53
|
padding: 1rem 1.25rem 1.5rem;
|
|
52
54
|
}
|
|
@@ -119,10 +121,10 @@ class b extends c {
|
|
|
119
121
|
color: #fff;
|
|
120
122
|
font-size: .75rem;
|
|
121
123
|
font-weight: 700;
|
|
122
|
-
padding: 0.125rem 0.
|
|
123
|
-
border-radius:
|
|
124
|
+
padding: 0.125rem 0.1875rem 0.05rem;
|
|
125
|
+
border-radius: 4px;
|
|
124
126
|
text-transform: uppercase;
|
|
125
|
-
background-color: #
|
|
127
|
+
background-color: #daa520; /* default (gold) */
|
|
126
128
|
letter-spacing: .03em;
|
|
127
129
|
}
|
|
128
130
|
.label.recommended-story {
|
|
@@ -190,7 +192,7 @@ class b extends c {
|
|
|
190
192
|
e.has("api") && e.get("api") !== this.api && this.load(), e.has("refreshInterval") && this._setupInterval();
|
|
191
193
|
}
|
|
192
194
|
async fetchActiveAlerts() {
|
|
193
|
-
return
|
|
195
|
+
return f({
|
|
194
196
|
baseUrl: this.api.replace(/v1\/.*$/, "")
|
|
195
197
|
}).listActiveAlerts();
|
|
196
198
|
}
|
|
@@ -199,7 +201,7 @@ class b extends c {
|
|
|
199
201
|
this.loading = !0, this.error = "";
|
|
200
202
|
try {
|
|
201
203
|
const e = await this.fetchActiveAlerts();
|
|
202
|
-
this.items = (e?.items || []).map(
|
|
204
|
+
this.items = (e?.items || []).map(b).filter(Boolean);
|
|
203
205
|
} catch (e) {
|
|
204
206
|
console.error("[wral-active-alerts]", e), this.items = [], this.error = "Unable to load active alerts.";
|
|
205
207
|
} finally {
|
|
@@ -216,10 +218,10 @@ class b extends c {
|
|
|
216
218
|
this._refreshId && (globalThis.clearInterval(this._refreshId), this._refreshId = null);
|
|
217
219
|
}
|
|
218
220
|
render() {
|
|
219
|
-
const { items: e, loading: s, error: a } = this, l = (r,
|
|
220
|
-
const
|
|
221
|
+
const { items: e, loading: s, error: a } = this, l = (r, n) => {
|
|
222
|
+
const o = v(r.effectiveFrom), c = String(r.topic || "").trim().toLowerCase();
|
|
221
223
|
return i`
|
|
222
|
-
<li class="alert" data-index=${
|
|
224
|
+
<li class="alert" data-index=${n} aria-label="Site Alert">
|
|
223
225
|
<div class="thumb">
|
|
224
226
|
<img
|
|
225
227
|
src=${r.image}
|
|
@@ -229,12 +231,12 @@ class b extends c {
|
|
|
229
231
|
</div>
|
|
230
232
|
<div class="alert-body">
|
|
231
233
|
<div class="alert-header">
|
|
232
|
-
<div class="label ${
|
|
233
|
-
${
|
|
234
|
+
<div class="label ${c}">
|
|
235
|
+
${u(r.caption)}
|
|
234
236
|
</div>
|
|
235
|
-
${
|
|
237
|
+
${o ? i`
|
|
236
238
|
<span class="date">
|
|
237
|
-
${
|
|
239
|
+
${o}
|
|
238
240
|
</span>
|
|
239
241
|
` : ""}
|
|
240
242
|
</div>
|
|
@@ -265,9 +267,9 @@ class b extends c {
|
|
|
265
267
|
`;
|
|
266
268
|
}
|
|
267
269
|
}
|
|
268
|
-
globalThis?.customElements && !globalThis.customElements.get("wral-active-alerts") && globalThis.customElements.define("wral-active-alerts",
|
|
270
|
+
globalThis?.customElements && !globalThis.customElements.get("wral-active-alerts") && globalThis.customElements.define("wral-active-alerts", y);
|
|
269
271
|
export {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
272
|
+
y as W,
|
|
273
|
+
b as n,
|
|
274
|
+
u as s
|
|
273
275
|
};
|