@wral/active-alerts 0.2.3 → 0.2.5
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
|
|
6
|
+
const H = globalThis, L = 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.");
|
|
@@ -32,7 +32,7 @@ const at = (i) => new tt(typeof i == "string" ? i : i + "", void 0, j), lt = (i,
|
|
|
32
32
|
}, ht = (i, t) => {
|
|
33
33
|
if (L) i.adoptedStyleSheets = t.map(((e) => e instanceof CSSStyleSheet ? e : e.styleSheet));
|
|
34
34
|
else for (const e of t) {
|
|
35
|
-
const s = document.createElement("style"), r =
|
|
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
38
|
}, q = L ? (i) => i : (i) => i instanceof CSSStyleSheet ? ((t) => {
|
|
@@ -45,10 +45,10 @@ 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:
|
|
48
|
+
const { is: ct, defineProperty: dt, getOwnPropertyDescriptor: pt, getOwnPropertyNames: ut, getOwnPropertySymbols: ft, getPrototypeOf: $t } = Object, k = globalThis, F = k.trustedTypes, mt = F ? F.emptyScript : "", gt = k.reactiveElementPolyfillSupport, x = (i, t) => i, z = { toAttribute(i, t) {
|
|
49
49
|
switch (t) {
|
|
50
50
|
case Boolean:
|
|
51
|
-
i = i ?
|
|
51
|
+
i = i ? mt : null;
|
|
52
52
|
break;
|
|
53
53
|
case Object:
|
|
54
54
|
case Array:
|
|
@@ -74,7 +74,7 @@ const { is: ct, defineProperty: dt, getOwnPropertyDescriptor: pt, getOwnProperty
|
|
|
74
74
|
}
|
|
75
75
|
return e;
|
|
76
76
|
} }, et = (i, t) => !ct(i, t), K = { attribute: !0, type: String, converter: z, reflect: !1, useDefault: !1, hasChanged: et };
|
|
77
|
-
Symbol.metadata ??= Symbol("metadata"),
|
|
77
|
+
Symbol.metadata ??= Symbol("metadata"), k.litPropertyMetadata ??= /* @__PURE__ */ new WeakMap();
|
|
78
78
|
let b = class extends HTMLElement {
|
|
79
79
|
static addInitializer(t) {
|
|
80
80
|
this._$Ei(), (this.l ??= []).push(t);
|
|
@@ -95,8 +95,8 @@ let b = class extends HTMLElement {
|
|
|
95
95
|
this[e] = o;
|
|
96
96
|
} };
|
|
97
97
|
return { get: r, set(o) {
|
|
98
|
-
const
|
|
99
|
-
n?.call(this, o), this.requestUpdate(t,
|
|
98
|
+
const d = r?.call(this);
|
|
99
|
+
n?.call(this, o), this.requestUpdate(t, d, s);
|
|
100
100
|
}, configurable: !0, enumerable: !0 };
|
|
101
101
|
}
|
|
102
102
|
static getPropertyOptions(t) {
|
|
@@ -104,7 +104,7 @@ let b = class extends HTMLElement {
|
|
|
104
104
|
}
|
|
105
105
|
static _$Ei() {
|
|
106
106
|
if (this.hasOwnProperty(x("elementProperties"))) return;
|
|
107
|
-
const t =
|
|
107
|
+
const t = $t(this);
|
|
108
108
|
t.finalize(), t.l !== void 0 && (this.l = [...t.l]), this.elementProperties = new Map(t.elementProperties);
|
|
109
109
|
}
|
|
110
110
|
static finalize() {
|
|
@@ -181,8 +181,8 @@ let b = class extends HTMLElement {
|
|
|
181
181
|
if (r !== void 0 && this._$Em !== r) {
|
|
182
182
|
const n = s.getPropertyOptions(r), o = typeof n.converter == "function" ? { fromAttribute: n.converter } : n.converter?.fromAttribute !== void 0 ? n.converter : z;
|
|
183
183
|
this._$Em = r;
|
|
184
|
-
const
|
|
185
|
-
this[r] =
|
|
184
|
+
const d = o.fromAttribute(e, n.type);
|
|
185
|
+
this[r] = d ?? this._$Ej?.get(r) ?? d, this._$Em = null;
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
requestUpdate(t, e, s) {
|
|
@@ -218,8 +218,8 @@ let b = class extends HTMLElement {
|
|
|
218
218
|
}
|
|
219
219
|
const s = this.constructor.elementProperties;
|
|
220
220
|
if (s.size > 0) for (const [r, n] of s) {
|
|
221
|
-
const { wrapped: o } = n,
|
|
222
|
-
o !== !0 || this._$AL.has(r) ||
|
|
221
|
+
const { wrapped: o } = n, d = this[r];
|
|
222
|
+
o !== !0 || this._$AL.has(r) || d === void 0 || this.C(r, void 0, n, d);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
let t = !1;
|
|
@@ -256,15 +256,15 @@ let b = class extends HTMLElement {
|
|
|
256
256
|
firstUpdated(t) {
|
|
257
257
|
}
|
|
258
258
|
};
|
|
259
|
-
b.elementStyles = [], b.shadowRootOptions = { mode: "open" }, b[x("elementProperties")] = /* @__PURE__ */ new Map(), b[x("finalized")] = /* @__PURE__ */ new Map(), gt?.({ ReactiveElement: b }), (
|
|
259
|
+
b.elementStyles = [], b.shadowRootOptions = { mode: "open" }, b[x("elementProperties")] = /* @__PURE__ */ new Map(), b[x("finalized")] = /* @__PURE__ */ new Map(), gt?.({ ReactiveElement: b }), (k.reactiveElementVersions ??= []).push("2.1.1");
|
|
260
260
|
/**
|
|
261
261
|
* @license
|
|
262
262
|
* Copyright 2017 Google LLC
|
|
263
263
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
264
264
|
*/
|
|
265
|
-
const D = globalThis,
|
|
265
|
+
const D = globalThis, I = D.trustedTypes, J = I ? I.createPolicy("lit-html", { createHTML: (i) => i }) : void 0, st = "$lit$", m = `lit$${Math.random().toFixed(9).slice(2)}$`, it = "?" + m, _t = `<${it}>`, A = document, P = () => A.createComment(""), U = (i) => i === null || typeof i != "object" && typeof i != "function", B = Array.isArray, yt = (i) => B(i) || typeof i?.[Symbol.iterator] == "function", R = `[
|
|
266
266
|
\f\r]`, w = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, Z = /-->/g, G = />/g, g = RegExp(`>|${R}(?:([^\\s"'>=/]+)(${R}*=${R}*(?:[^
|
|
267
|
-
\f\r"'\`<>=]|("|')|))|$)`, "g"), Q = /'/g, X = /"/g, rt = /^(?:script|style|textarea|title)$/i, At = (i) => (t, ...e) => ({ _$litType$: i, strings: t, values: e }),
|
|
267
|
+
\f\r"'\`<>=]|("|')|))|$)`, "g"), Q = /'/g, X = /"/g, rt = /^(?:script|style|textarea|title)$/i, At = (i) => (t, ...e) => ({ _$litType$: i, strings: t, values: e }), $ = At(1), E = Symbol.for("lit-noChange"), p = Symbol.for("lit-nothing"), Y = /* @__PURE__ */ new WeakMap(), y = A.createTreeWalker(A, 129);
|
|
268
268
|
function nt(i, t) {
|
|
269
269
|
if (!B(i) || !i.hasOwnProperty("raw")) throw Error("invalid template strings array");
|
|
270
270
|
return J !== void 0 ? J.createHTML(t) : t;
|
|
@@ -272,12 +272,12 @@ function nt(i, t) {
|
|
|
272
272
|
const vt = (i, t) => {
|
|
273
273
|
const e = i.length - 1, s = [];
|
|
274
274
|
let r, n = t === 2 ? "<svg>" : t === 3 ? "<math>" : "", o = w;
|
|
275
|
-
for (let
|
|
276
|
-
const a = i[
|
|
277
|
-
let
|
|
278
|
-
for (; u < a.length && (o.lastIndex = u, l = o.exec(a), l !== null); ) u = o.lastIndex, o === w ? l[1] === "!--" ? o = Z : l[1] !== void 0 ? o = G : l[2] !== void 0 ? (rt.test(l[2]) && (r = RegExp("</" + l[2], "g")), o = g) : l[3] !== void 0 && (o = g) : o === g ? l[0] === ">" ? (o = r ?? w, h = -1) : l[1] === void 0 ? h = -2 : (h = o.lastIndex - l[2].length,
|
|
279
|
-
const
|
|
280
|
-
n += o === w ? a + _t : h >= 0 ? (s.push(
|
|
275
|
+
for (let d = 0; d < e; d++) {
|
|
276
|
+
const a = i[d];
|
|
277
|
+
let c, l, h = -1, u = 0;
|
|
278
|
+
for (; u < a.length && (o.lastIndex = u, l = o.exec(a), l !== null); ) u = o.lastIndex, o === w ? l[1] === "!--" ? o = Z : l[1] !== void 0 ? o = G : l[2] !== void 0 ? (rt.test(l[2]) && (r = RegExp("</" + l[2], "g")), o = g) : l[3] !== void 0 && (o = g) : o === g ? l[0] === ">" ? (o = r ?? w, h = -1) : l[1] === void 0 ? h = -2 : (h = o.lastIndex - l[2].length, c = l[1], o = l[3] === void 0 ? g : l[3] === '"' ? X : Q) : o === X || o === Q ? o = g : o === Z || o === G ? o = w : (o = g, r = void 0);
|
|
279
|
+
const f = o === g && i[d + 1].startsWith("/>") ? " " : "";
|
|
280
|
+
n += o === w ? a + _t : h >= 0 ? (s.push(c), a.slice(0, h) + st + a.slice(h) + m + f) : a + m + (h === -2 ? d : f);
|
|
281
281
|
}
|
|
282
282
|
return [nt(i, n + (i[e] || "<?>") + (t === 2 ? "</svg>" : t === 3 ? "</math>" : "")), s];
|
|
283
283
|
};
|
|
@@ -286,29 +286,29 @@ class T {
|
|
|
286
286
|
let r;
|
|
287
287
|
this.parts = [];
|
|
288
288
|
let n = 0, o = 0;
|
|
289
|
-
const
|
|
290
|
-
if (this.el = T.createElement(
|
|
289
|
+
const d = t.length - 1, a = this.parts, [c, l] = vt(t, e);
|
|
290
|
+
if (this.el = T.createElement(c, s), y.currentNode = this.el.content, e === 2 || e === 3) {
|
|
291
291
|
const h = this.el.content.firstChild;
|
|
292
292
|
h.replaceWith(...h.childNodes);
|
|
293
293
|
}
|
|
294
|
-
for (; (r = y.nextNode()) !== null && a.length <
|
|
294
|
+
for (; (r = y.nextNode()) !== null && a.length < d; ) {
|
|
295
295
|
if (r.nodeType === 1) {
|
|
296
296
|
if (r.hasAttributes()) for (const h of r.getAttributeNames()) if (h.endsWith(st)) {
|
|
297
|
-
const u = l[o++],
|
|
298
|
-
a.push({ type: 1, index: n, name: N[2], strings:
|
|
299
|
-
} else h.startsWith(
|
|
297
|
+
const u = l[o++], f = r.getAttribute(h).split(m), N = /([.?@])?(.*)/.exec(u);
|
|
298
|
+
a.push({ type: 1, index: n, name: N[2], strings: f, ctor: N[1] === "." ? Et : N[1] === "?" ? St : N[1] === "@" ? wt : M }), r.removeAttribute(h);
|
|
299
|
+
} else h.startsWith(m) && (a.push({ type: 6, index: n }), r.removeAttribute(h));
|
|
300
300
|
if (rt.test(r.tagName)) {
|
|
301
|
-
const h = r.textContent.split(
|
|
301
|
+
const h = r.textContent.split(m), u = h.length - 1;
|
|
302
302
|
if (u > 0) {
|
|
303
|
-
r.textContent =
|
|
304
|
-
for (let
|
|
303
|
+
r.textContent = I ? I.emptyScript : "";
|
|
304
|
+
for (let f = 0; f < u; f++) r.append(h[f], P()), y.nextNode(), a.push({ type: 2, index: ++n });
|
|
305
305
|
r.append(h[u], P());
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
308
|
} else if (r.nodeType === 8) if (r.data === it) a.push({ type: 2, index: n });
|
|
309
309
|
else {
|
|
310
310
|
let h = -1;
|
|
311
|
-
for (; (h = r.data.indexOf(
|
|
311
|
+
for (; (h = r.data.indexOf(m, h + 1)) !== -1; ) a.push({ type: 7, index: n }), h += m.length - 1;
|
|
312
312
|
}
|
|
313
313
|
n++;
|
|
314
314
|
}
|
|
@@ -337,11 +337,11 @@ class bt {
|
|
|
337
337
|
u(t) {
|
|
338
338
|
const { el: { content: e }, parts: s } = this._$AD, r = (t?.creationScope ?? A).importNode(e, !0);
|
|
339
339
|
y.currentNode = r;
|
|
340
|
-
let n = y.nextNode(), o = 0,
|
|
340
|
+
let n = y.nextNode(), o = 0, d = 0, a = s[0];
|
|
341
341
|
for (; a !== void 0; ) {
|
|
342
342
|
if (o === a.index) {
|
|
343
|
-
let
|
|
344
|
-
a.type === 2 ?
|
|
343
|
+
let c;
|
|
344
|
+
a.type === 2 ? c = new O(n, n.nextSibling, this, t) : a.type === 1 ? c = new a.ctor(n, a.name, a.strings, this, t) : a.type === 6 && (c = new xt(n, this, t)), this._$AV.push(c), a = s[++d];
|
|
345
345
|
}
|
|
346
346
|
o !== a?.index && (n = y.nextNode(), o++);
|
|
347
347
|
}
|
|
@@ -426,9 +426,9 @@ class M {
|
|
|
426
426
|
let o = !1;
|
|
427
427
|
if (n === void 0) t = S(this, t, e, 0), o = !U(t) || t !== this._$AH && t !== E, o && (this._$AH = t);
|
|
428
428
|
else {
|
|
429
|
-
const
|
|
430
|
-
let a,
|
|
431
|
-
for (t = n[0], a = 0; a < n.length - 1; a++)
|
|
429
|
+
const d = t;
|
|
430
|
+
let a, c;
|
|
431
|
+
for (t = n[0], a = 0; a < n.length - 1; a++) c = S(this, d[s + a], e, a), c === E && (c = this._$AH[a]), o ||= !U(c) || c !== this._$AH[a], c === p ? t = p : t !== p && (t += (c ?? "") + n[a + 1]), this._$AH[a] = c;
|
|
432
432
|
}
|
|
433
433
|
o && !r && this.j(t);
|
|
434
434
|
}
|
|
@@ -526,9 +526,9 @@ function Tt(i) {
|
|
|
526
526
|
api: _(v, i),
|
|
527
527
|
listActiveAlerts: _(Ot, i),
|
|
528
528
|
getActiveAlert: _(Nt, i),
|
|
529
|
-
listAlerts: _(
|
|
530
|
-
getAlert: _(
|
|
531
|
-
sendAlert: _(
|
|
529
|
+
listAlerts: _(Ht, i),
|
|
530
|
+
getAlert: _(It, i),
|
|
531
|
+
sendAlert: _(kt, i),
|
|
532
532
|
cancelAlert: _(Mt, i)
|
|
533
533
|
};
|
|
534
534
|
}
|
|
@@ -540,13 +540,13 @@ function Nt(i, t) {
|
|
|
540
540
|
const e = Object.assign({}, i, { apiKey: void 0 });
|
|
541
541
|
return v(e, `/v1/active/alerts/${t}`);
|
|
542
542
|
}
|
|
543
|
-
function
|
|
543
|
+
function Ht(i) {
|
|
544
544
|
return v(i, "/v1/alerts");
|
|
545
545
|
}
|
|
546
|
-
function
|
|
546
|
+
function It(i, t) {
|
|
547
547
|
return v(i, `/v1/alerts/${t}`);
|
|
548
548
|
}
|
|
549
|
-
function
|
|
549
|
+
function kt(i, t) {
|
|
550
550
|
return v(i, "/v1/alerts", {
|
|
551
551
|
method: "POST",
|
|
552
552
|
body: t
|
|
@@ -562,10 +562,10 @@ async function v(i, t, e) {
|
|
|
562
562
|
"Content-Type": "application/json"
|
|
563
563
|
};
|
|
564
564
|
i.apiKey && (o.Authorization = `Bearer ${i.apiKey}`);
|
|
565
|
-
const
|
|
565
|
+
const d = Object.assign({}, e, {
|
|
566
566
|
headers: Object.assign({}, o, e?.headers),
|
|
567
567
|
body: e?.body ? JSON.stringify(e.body) : void 0
|
|
568
|
-
}), a = await fetch(n.toString(),
|
|
568
|
+
}), a = await fetch(n.toString(), d);
|
|
569
569
|
if (!a.ok) {
|
|
570
570
|
const l = new Error("API request failed.", { cause: a });
|
|
571
571
|
if (l.status = a.status, l.statusText = a.statusText, l.url = n.toString(), l.headers = a.headers, l.bodyUsed = a.bodyUsed, a.headers.get("Content-Type")?.includes("application/json"))
|
|
@@ -578,8 +578,8 @@ async function v(i, t, e) {
|
|
|
578
578
|
}
|
|
579
579
|
if (a.status === 204)
|
|
580
580
|
return;
|
|
581
|
-
const
|
|
582
|
-
return
|
|
581
|
+
const c = await a.json();
|
|
582
|
+
return c.caption && console.warn("Alert API provided a value with a caption field. The caption field is deprecated and will be removed."), (c?.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."), c;
|
|
583
583
|
}
|
|
584
584
|
const Rt = {
|
|
585
585
|
lg: 1366
|
|
@@ -664,13 +664,26 @@ class ot extends C {
|
|
|
664
664
|
gap: .75rem;
|
|
665
665
|
}
|
|
666
666
|
.alert {
|
|
667
|
+
margin: 0;
|
|
668
|
+
}
|
|
669
|
+
.alert-card {
|
|
667
670
|
background: #fff;
|
|
668
671
|
border: 1px solid #e5e5e5;
|
|
669
672
|
padding: .9rem 1rem;
|
|
670
673
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
|
|
671
674
|
display: grid;
|
|
672
|
-
grid-template-columns:
|
|
675
|
+
grid-template-columns: 240px 1fr;
|
|
673
676
|
gap: .9rem;
|
|
677
|
+
color: inherit;
|
|
678
|
+
text-decoration: none;
|
|
679
|
+
}
|
|
680
|
+
.alert-card:hover .title,
|
|
681
|
+
.alert-card:focus-visible .title {
|
|
682
|
+
text-decoration: underline;
|
|
683
|
+
}
|
|
684
|
+
.alert-card:focus-visible {
|
|
685
|
+
outline: 2px solid #000b27;
|
|
686
|
+
outline-offset: 2px;
|
|
674
687
|
}
|
|
675
688
|
.thumb {
|
|
676
689
|
overflow: hidden;
|
|
@@ -711,7 +724,7 @@ class ot extends C {
|
|
|
711
724
|
.label.recommended-story {
|
|
712
725
|
background-color: #2594e3;
|
|
713
726
|
}
|
|
714
|
-
|
|
727
|
+
.title {
|
|
715
728
|
color: inherit;
|
|
716
729
|
font-size: 1.0625rem;
|
|
717
730
|
line-height: 1.35;
|
|
@@ -719,16 +732,6 @@ class ot extends C {
|
|
|
719
732
|
font-weight: 700;
|
|
720
733
|
text-decoration: none;
|
|
721
734
|
}
|
|
722
|
-
a.title:hover,
|
|
723
|
-
a.title:focus-visible {
|
|
724
|
-
text-decoration: underline;
|
|
725
|
-
}
|
|
726
|
-
.title.no-link {
|
|
727
|
-
font-size: 1.0625rem;
|
|
728
|
-
line-height: 1.35;
|
|
729
|
-
font-family: var(--heading-font-family, sans-serif);
|
|
730
|
-
font-weight: 700;
|
|
731
|
-
}
|
|
732
735
|
.body {
|
|
733
736
|
margin: 0;
|
|
734
737
|
color: #323232;
|
|
@@ -756,14 +759,6 @@ class ot extends C {
|
|
|
756
759
|
}
|
|
757
760
|
@media (max-width: 720px) {
|
|
758
761
|
.wrapper { padding: .75rem .75rem 1.25rem; }
|
|
759
|
-
.alert {
|
|
760
|
-
grid-template-columns: 1fr;
|
|
761
|
-
padding: .85rem .9rem;
|
|
762
|
-
}
|
|
763
|
-
.alert-header {
|
|
764
|
-
align-items: flex-start;
|
|
765
|
-
flex-direction: column;
|
|
766
|
-
}
|
|
767
762
|
}
|
|
768
763
|
`;
|
|
769
764
|
async firstUpdated() {
|
|
@@ -806,49 +801,55 @@ class ot extends C {
|
|
|
806
801
|
}
|
|
807
802
|
render() {
|
|
808
803
|
const { items: t, loading: e, error: s } = this, r = (n, o) => {
|
|
809
|
-
const
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
804
|
+
const d = Bt(n.effectiveFrom), a = String(n.topic || "").trim().toLowerCase(), c = n.title || n.body, l = String(n.title || "").trim(), h = String(n.body || "").trim(), u = l && h && l !== h ? n.body : "", f = $`
|
|
805
|
+
<div class="thumb">
|
|
806
|
+
<img
|
|
807
|
+
src=${n.image}
|
|
808
|
+
alt=${n.title}
|
|
809
|
+
loading="lazy"
|
|
810
|
+
>
|
|
811
|
+
</div>
|
|
812
|
+
<div class="alert-body">
|
|
813
|
+
<div class="alert-header">
|
|
814
|
+
<div class="label ${a}">
|
|
815
|
+
${jt(n.caption)}
|
|
818
816
|
</div>
|
|
819
|
-
|
|
820
|
-
<
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
817
|
+
${d ? $`
|
|
818
|
+
<span class="date">
|
|
819
|
+
${d}
|
|
820
|
+
</span>
|
|
821
|
+
` : ""}
|
|
822
|
+
</div>
|
|
823
|
+
<div class="title">${c}</div>
|
|
824
|
+
${u ? $`<p class="body">${u}</p>` : ""}
|
|
825
|
+
</div>
|
|
826
|
+
`;
|
|
827
|
+
return $`
|
|
828
|
+
<li class="alert" data-index=${o} aria-label="Site Alert">
|
|
829
|
+
${n.url ? $`
|
|
830
|
+
<a class="alert-card" href=${n.url} aria-label=${c}>
|
|
831
|
+
${f}
|
|
832
|
+
</a>
|
|
833
|
+
` : $`
|
|
834
|
+
<div class="alert-card">
|
|
835
|
+
${f}
|
|
835
836
|
</div>
|
|
836
|
-
|
|
837
|
+
`}
|
|
838
|
+
</li>
|
|
837
839
|
`;
|
|
838
840
|
};
|
|
839
|
-
return
|
|
841
|
+
return $`
|
|
840
842
|
<div class="wrapper" role="region" aria-live="polite">
|
|
841
843
|
<div class="heading">
|
|
842
|
-
|
|
843
|
-
${e ? f`<span class="pill">Loading…</span>` : ""}
|
|
844
|
+
${e ? $`<span class="pill">Loading…</span>` : ""}
|
|
844
845
|
</div>
|
|
845
846
|
|
|
846
|
-
${s ?
|
|
847
|
-
${!s && !e && !t.length ?
|
|
847
|
+
${s ? $`<div class="status error">${s}</div>` : ""}
|
|
848
|
+
${!s && !e && !t.length ? $`
|
|
848
849
|
<div class="empty">No active alerts right now.</div>
|
|
849
850
|
` : ""}
|
|
850
851
|
|
|
851
|
-
${t.length ?
|
|
852
|
+
${t.length ? $`
|
|
852
853
|
<ul class="list">
|
|
853
854
|
${t.map(r)}
|
|
854
855
|
</ul>
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { LitElement as
|
|
2
|
-
import { createClient as
|
|
3
|
-
const
|
|
1
|
+
import { LitElement as g, css as u, html as i } from "lit";
|
|
2
|
+
import { createClient as b } from "@wral/sdk-alerts/v1";
|
|
3
|
+
const v = {
|
|
4
4
|
lg: 1366
|
|
5
|
-
},
|
|
5
|
+
}, y = "https://api.wral.com/alerts/v1/active/alerts", x = "https://assets.wral.com/a1cc0e86-adab-48e9-bd80-703cd2c56aff?w=1200&h=630", $ = (e) => String(e || "Alert").replace(/[^\p{L}\p{N}]/gu, " ").replace(/\s+/g, " ").trim() || "Alert", I = (e) => {
|
|
6
6
|
if (!e) return null;
|
|
7
7
|
const t = e.link || e.url || e.href || "", s = e.title || e.headline || "";
|
|
8
8
|
if (!s) return null;
|
|
9
|
-
const a = String(e.topic || "").trim(), l = a.toLowerCase(), r = e.caption || a || "Alert", n = e.image || e.imageUrl || e.image_url ||
|
|
9
|
+
const a = String(e.topic || "").trim(), l = a.toLowerCase(), r = e.caption || a || "Alert", n = e.image || e.imageUrl || e.image_url || x;
|
|
10
10
|
return {
|
|
11
11
|
url: t,
|
|
12
12
|
title: s,
|
|
@@ -16,7 +16,7 @@ const p = {
|
|
|
16
16
|
body: e.body || e.summary || "",
|
|
17
17
|
effectiveFrom: e.effectiveFrom || e.effective_from || ""
|
|
18
18
|
};
|
|
19
|
-
},
|
|
19
|
+
}, A = (e) => {
|
|
20
20
|
if (!e) return "";
|
|
21
21
|
try {
|
|
22
22
|
const t = new Date(e);
|
|
@@ -30,7 +30,7 @@ const p = {
|
|
|
30
30
|
return "";
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
|
-
class
|
|
33
|
+
class _ extends g {
|
|
34
34
|
static properties = {
|
|
35
35
|
api: { type: String },
|
|
36
36
|
items: { state: !0 },
|
|
@@ -39,16 +39,16 @@ class y extends d {
|
|
|
39
39
|
refreshInterval: { type: Number, attribute: "refresh-interval" }
|
|
40
40
|
};
|
|
41
41
|
constructor() {
|
|
42
|
-
super(), this.api =
|
|
42
|
+
super(), this.api = y, this.items = [], this.loading = !1, this.error = "", this.refreshInterval = 0, this._refreshId = null;
|
|
43
43
|
}
|
|
44
|
-
static styles =
|
|
44
|
+
static styles = u`
|
|
45
45
|
:host {
|
|
46
46
|
display: block;
|
|
47
47
|
background: #f7f5f4;
|
|
48
48
|
color: #000b27;
|
|
49
49
|
}
|
|
50
50
|
.wrapper {
|
|
51
|
-
max-width: ${
|
|
51
|
+
max-width: ${v.lg}px;
|
|
52
52
|
margin: 0 auto;
|
|
53
53
|
padding: 1rem 1.25rem 1.5rem;
|
|
54
54
|
}
|
|
@@ -83,13 +83,26 @@ class y extends d {
|
|
|
83
83
|
gap: .75rem;
|
|
84
84
|
}
|
|
85
85
|
.alert {
|
|
86
|
+
margin: 0;
|
|
87
|
+
}
|
|
88
|
+
.alert-card {
|
|
86
89
|
background: #fff;
|
|
87
90
|
border: 1px solid #e5e5e5;
|
|
88
91
|
padding: .9rem 1rem;
|
|
89
92
|
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
|
|
90
93
|
display: grid;
|
|
91
|
-
grid-template-columns:
|
|
94
|
+
grid-template-columns: 240px 1fr;
|
|
92
95
|
gap: .9rem;
|
|
96
|
+
color: inherit;
|
|
97
|
+
text-decoration: none;
|
|
98
|
+
}
|
|
99
|
+
.alert-card:hover .title,
|
|
100
|
+
.alert-card:focus-visible .title {
|
|
101
|
+
text-decoration: underline;
|
|
102
|
+
}
|
|
103
|
+
.alert-card:focus-visible {
|
|
104
|
+
outline: 2px solid #000b27;
|
|
105
|
+
outline-offset: 2px;
|
|
93
106
|
}
|
|
94
107
|
.thumb {
|
|
95
108
|
overflow: hidden;
|
|
@@ -130,7 +143,7 @@ class y extends d {
|
|
|
130
143
|
.label.recommended-story {
|
|
131
144
|
background-color: #2594e3;
|
|
132
145
|
}
|
|
133
|
-
|
|
146
|
+
.title {
|
|
134
147
|
color: inherit;
|
|
135
148
|
font-size: 1.0625rem;
|
|
136
149
|
line-height: 1.35;
|
|
@@ -138,16 +151,6 @@ class y extends d {
|
|
|
138
151
|
font-weight: 700;
|
|
139
152
|
text-decoration: none;
|
|
140
153
|
}
|
|
141
|
-
a.title:hover,
|
|
142
|
-
a.title:focus-visible {
|
|
143
|
-
text-decoration: underline;
|
|
144
|
-
}
|
|
145
|
-
.title.no-link {
|
|
146
|
-
font-size: 1.0625rem;
|
|
147
|
-
line-height: 1.35;
|
|
148
|
-
font-family: var(--heading-font-family, sans-serif);
|
|
149
|
-
font-weight: 700;
|
|
150
|
-
}
|
|
151
154
|
.body {
|
|
152
155
|
margin: 0;
|
|
153
156
|
color: #323232;
|
|
@@ -175,14 +178,6 @@ class y extends d {
|
|
|
175
178
|
}
|
|
176
179
|
@media (max-width: 720px) {
|
|
177
180
|
.wrapper { padding: .75rem .75rem 1.25rem; }
|
|
178
|
-
.alert {
|
|
179
|
-
grid-template-columns: 1fr;
|
|
180
|
-
padding: .85rem .9rem;
|
|
181
|
-
}
|
|
182
|
-
.alert-header {
|
|
183
|
-
align-items: flex-start;
|
|
184
|
-
flex-direction: column;
|
|
185
|
-
}
|
|
186
181
|
}
|
|
187
182
|
`;
|
|
188
183
|
async firstUpdated() {
|
|
@@ -198,7 +193,7 @@ class y extends d {
|
|
|
198
193
|
t.has("api") && t.get("api") !== this.api && this.load(), t.has("refreshInterval") && this._setupInterval();
|
|
199
194
|
}
|
|
200
195
|
async fetchActiveAlerts() {
|
|
201
|
-
return
|
|
196
|
+
return b({
|
|
202
197
|
baseUrl: this.api.replace(/v1\/.*$/, "")
|
|
203
198
|
}).listActiveAlerts();
|
|
204
199
|
}
|
|
@@ -207,7 +202,7 @@ class y extends d {
|
|
|
207
202
|
this.loading = !0, this.error = "";
|
|
208
203
|
try {
|
|
209
204
|
const t = await this.fetchActiveAlerts();
|
|
210
|
-
this.items = (t?.items || []).map(
|
|
205
|
+
this.items = (t?.items || []).map(I).filter(Boolean);
|
|
211
206
|
} catch (t) {
|
|
212
207
|
console.error("[wral-active-alerts]", t), this.items = [], this.error = "Unable to load active alerts.";
|
|
213
208
|
} finally {
|
|
@@ -225,40 +220,46 @@ class y extends d {
|
|
|
225
220
|
}
|
|
226
221
|
render() {
|
|
227
222
|
const { items: t, loading: s, error: a } = this, l = (r, n) => {
|
|
228
|
-
const o =
|
|
223
|
+
const o = A(r.effectiveFrom), h = String(r.topic || "").trim().toLowerCase(), c = r.title || r.body, d = String(r.title || "").trim(), m = String(r.body || "").trim(), f = d && m && d !== m ? r.body : "", p = i`
|
|
224
|
+
<div class="thumb">
|
|
225
|
+
<img
|
|
226
|
+
src=${r.image}
|
|
227
|
+
alt=${r.title}
|
|
228
|
+
loading="lazy"
|
|
229
|
+
>
|
|
230
|
+
</div>
|
|
231
|
+
<div class="alert-body">
|
|
232
|
+
<div class="alert-header">
|
|
233
|
+
<div class="label ${h}">
|
|
234
|
+
${$(r.caption)}
|
|
235
|
+
</div>
|
|
236
|
+
${o ? i`
|
|
237
|
+
<span class="date">
|
|
238
|
+
${o}
|
|
239
|
+
</span>
|
|
240
|
+
` : ""}
|
|
241
|
+
</div>
|
|
242
|
+
<div class="title">${c}</div>
|
|
243
|
+
${f ? i`<p class="body">${f}</p>` : ""}
|
|
244
|
+
</div>
|
|
245
|
+
`;
|
|
229
246
|
return i`
|
|
230
247
|
<li class="alert" data-index=${n} aria-label="Site Alert">
|
|
231
|
-
|
|
232
|
-
<
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
>
|
|
237
|
-
|
|
238
|
-
<div class="alert-body">
|
|
239
|
-
<div class="alert-header">
|
|
240
|
-
<div class="label ${c}">
|
|
241
|
-
${u(r.caption)}
|
|
242
|
-
</div>
|
|
243
|
-
${o ? i`
|
|
244
|
-
<span class="date">
|
|
245
|
-
${o}
|
|
246
|
-
</span>
|
|
247
|
-
` : ""}
|
|
248
|
-
</div>
|
|
249
|
-
${r.url ? i`
|
|
250
|
-
<a class="title" href=${r.url}>${r.body || r.title}</a>
|
|
251
|
-
` : i`
|
|
252
|
-
<div class="title no-link">${r.body || r.title}</div>
|
|
253
|
-
`}
|
|
248
|
+
${r.url ? i`
|
|
249
|
+
<a class="alert-card" href=${r.url} aria-label=${c}>
|
|
250
|
+
${p}
|
|
251
|
+
</a>
|
|
252
|
+
` : i`
|
|
253
|
+
<div class="alert-card">
|
|
254
|
+
${p}
|
|
254
255
|
</div>
|
|
255
|
-
|
|
256
|
+
`}
|
|
257
|
+
</li>
|
|
256
258
|
`;
|
|
257
259
|
};
|
|
258
260
|
return i`
|
|
259
261
|
<div class="wrapper" role="region" aria-live="polite">
|
|
260
262
|
<div class="heading">
|
|
261
|
-
<span>Active Alerts</span>
|
|
262
263
|
${s ? i`<span class="pill">Loading…</span>` : ""}
|
|
263
264
|
</div>
|
|
264
265
|
|
|
@@ -276,9 +277,9 @@ class y extends d {
|
|
|
276
277
|
`;
|
|
277
278
|
}
|
|
278
279
|
}
|
|
279
|
-
globalThis?.customElements && !globalThis.customElements.get("wral-active-alerts") && globalThis.customElements.define("wral-active-alerts",
|
|
280
|
+
globalThis?.customElements && !globalThis.customElements.get("wral-active-alerts") && globalThis.customElements.define("wral-active-alerts", _);
|
|
280
281
|
export {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
282
|
+
_ as W,
|
|
283
|
+
I as n,
|
|
284
|
+
$ as s
|
|
284
285
|
};
|