@wral/active-alerts 0.2.0 → 0.2.2
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 k = globalThis, L = k.ShadowRoot && (k.ShadyCSS === void 0 || k.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 (L && 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 (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 = k.litNonce;
|
|
36
36
|
r !== void 0 && s.setAttribute("nonce", r), s.textContent = e.cssText, i.appendChild(s);
|
|
37
37
|
}
|
|
38
|
-
}, q =
|
|
38
|
+
}, q = L ? (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,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: mt } = Object, I = globalThis, F = I.trustedTypes, $t = F ? F.emptyScript : "", gt = I.reactiveElementPolyfillSupport, x = (i, t) => i, z = { toAttribute(i, t) {
|
|
49
49
|
switch (t) {
|
|
50
50
|
case Boolean:
|
|
51
|
-
i = i ?
|
|
51
|
+
i = i ? $t : null;
|
|
52
52
|
break;
|
|
53
53
|
case Object:
|
|
54
54
|
case Array:
|
|
@@ -73,8 +73,8 @@ 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:
|
|
77
|
-
Symbol.metadata ??= Symbol("metadata"),
|
|
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"), I.litPropertyMetadata ??= /* @__PURE__ */ new WeakMap();
|
|
78
78
|
let b = class extends HTMLElement {
|
|
79
79
|
static addInitializer(t) {
|
|
80
80
|
this._$Ei(), (this.l ??= []).push(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 = mt(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() {
|
|
@@ -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 : z).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 : z;
|
|
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;
|
|
@@ -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 }), (I.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, H = D.trustedTypes, J = H ? H.createPolicy("lit-html", { createHTML: (i) => i }) : void 0, st = "$lit$", $ = `lit$${Math.random().toFixed(9).slice(2)}$`, it = "?" + $, _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,
|
|
267
|
+
\f\r"'\`<>=]|("|')|))|$)`, "g"), Q = /'/g, X = /"/g, rt = /^(?:script|style|textarea|title)$/i, At = (i) => (t, ...e) => ({ _$litType$: i, strings: t, values: e }), f = 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;
|
|
@@ -276,8 +276,8 @@ const vt = (i, t) => {
|
|
|
276
276
|
const a = i[c];
|
|
277
277
|
let d, l, h = -1, u = 0;
|
|
278
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, d = 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
|
|
280
|
-
n += o === w ? a + _t : h >= 0 ? (s.push(d), a.slice(0, h) + st + a.slice(h) +
|
|
279
|
+
const m = o === g && i[c + 1].startsWith("/>") ? " " : "";
|
|
280
|
+
n += o === w ? a + _t : h >= 0 ? (s.push(d), a.slice(0, h) + st + a.slice(h) + $ + m) : a + $ + (h === -2 ? c : m);
|
|
281
281
|
}
|
|
282
282
|
return [nt(i, n + (i[e] || "<?>") + (t === 2 ? "</svg>" : t === 3 ? "</math>" : "")), s];
|
|
283
283
|
};
|
|
@@ -287,34 +287,34 @@ class T {
|
|
|
287
287
|
this.parts = [];
|
|
288
288
|
let n = 0, o = 0;
|
|
289
289
|
const c = t.length - 1, a = this.parts, [d, l] = vt(t, e);
|
|
290
|
-
if (this.el = T.createElement(d, s),
|
|
290
|
+
if (this.el = T.createElement(d, 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 =
|
|
294
|
+
for (; (r = y.nextNode()) !== null && a.length < c; ) {
|
|
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++], m = r.getAttribute(h).split($), N = /([.?@])?(.*)/.exec(u);
|
|
298
|
+
a.push({ type: 1, index: n, name: N[2], strings: m, ctor: N[1] === "." ? Et : N[1] === "?" ? St : N[1] === "@" ? wt : M }), r.removeAttribute(h);
|
|
299
|
+
} else h.startsWith($) && (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($), u = h.length - 1;
|
|
302
302
|
if (u > 0) {
|
|
303
|
-
r.textContent =
|
|
304
|
-
for (let
|
|
303
|
+
r.textContent = H ? H.emptyScript : "";
|
|
304
|
+
for (let m = 0; m < u; m++) r.append(h[m], 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($, h + 1)) !== -1; ) a.push({ type: 7, index: n }), h += $.length - 1;
|
|
312
312
|
}
|
|
313
313
|
n++;
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
316
|
static createElement(t, e) {
|
|
317
|
-
const s =
|
|
317
|
+
const s = A.createElement("template");
|
|
318
318
|
return s.innerHTML = t, s;
|
|
319
319
|
}
|
|
320
320
|
}
|
|
@@ -335,17 +335,17 @@ class bt {
|
|
|
335
335
|
return this._$AM._$AU;
|
|
336
336
|
}
|
|
337
337
|
u(t) {
|
|
338
|
-
const { el: { content: e }, parts: s } = this._$AD, r = (t?.creationScope ??
|
|
339
|
-
|
|
340
|
-
let n =
|
|
338
|
+
const { el: { content: e }, parts: s } = this._$AD, r = (t?.creationScope ?? A).importNode(e, !0);
|
|
339
|
+
y.currentNode = r;
|
|
340
|
+
let n = y.nextNode(), o = 0, c = 0, a = s[0];
|
|
341
341
|
for (; a !== void 0; ) {
|
|
342
342
|
if (o === a.index) {
|
|
343
343
|
let d;
|
|
344
344
|
a.type === 2 ? d = new O(n, n.nextSibling, this, t) : a.type === 1 ? d = new a.ctor(n, a.name, a.strings, this, t) : a.type === 6 && (d = new xt(n, this, t)), this._$AV.push(d), a = s[++c];
|
|
345
345
|
}
|
|
346
|
-
o !== a?.index && (n =
|
|
346
|
+
o !== a?.index && (n = y.nextNode(), o++);
|
|
347
347
|
}
|
|
348
|
-
return
|
|
348
|
+
return y.currentNode = A, r;
|
|
349
349
|
}
|
|
350
350
|
p(t) {
|
|
351
351
|
let e = 0;
|
|
@@ -371,7 +371,7 @@ class O {
|
|
|
371
371
|
return this._$AB;
|
|
372
372
|
}
|
|
373
373
|
_$AI(t, e = this) {
|
|
374
|
-
t = S(this, t, e), U(t) ? t === p || t == null || t === "" ? (this._$AH !== p && this._$AR(), this._$AH = p) : t !== this._$AH && t !== E && this._(t) : t._$litType$ !== void 0 ? this.$(t) : t.nodeType !== void 0 ? this.T(t) :
|
|
374
|
+
t = S(this, t, e), U(t) ? t === p || t == null || t === "" ? (this._$AH !== p && this._$AR(), this._$AH = p) : t !== this._$AH && t !== E && this._(t) : t._$litType$ !== void 0 ? this.$(t) : t.nodeType !== void 0 ? this.T(t) : yt(t) ? this.k(t) : this._(t);
|
|
375
375
|
}
|
|
376
376
|
O(t) {
|
|
377
377
|
return this._$AA.parentNode.insertBefore(t, this._$AB);
|
|
@@ -380,7 +380,7 @@ class O {
|
|
|
380
380
|
this._$AH !== t && (this._$AR(), this._$AH = this.O(t));
|
|
381
381
|
}
|
|
382
382
|
_(t) {
|
|
383
|
-
this._$AH !== p && U(this._$AH) ? this._$AA.nextSibling.data = t : this.T(
|
|
383
|
+
this._$AH !== p && U(this._$AH) ? this._$AA.nextSibling.data = t : this.T(A.createTextNode(t)), this._$AH = t;
|
|
384
384
|
}
|
|
385
385
|
$(t) {
|
|
386
386
|
const { values: e, _$litType$: s } = t, r = typeof s == "number" ? this._$AC(t) : (s.el === void 0 && (s.el = T.createElement(nt(s.h, s.h[0]), this.options)), s);
|
|
@@ -411,7 +411,7 @@ class O {
|
|
|
411
411
|
this._$AM === void 0 && (this._$Cv = t, this._$AP?.(t));
|
|
412
412
|
}
|
|
413
413
|
}
|
|
414
|
-
class
|
|
414
|
+
class M {
|
|
415
415
|
get tagName() {
|
|
416
416
|
return this.element.tagName;
|
|
417
417
|
}
|
|
@@ -436,7 +436,7 @@ class k {
|
|
|
436
436
|
t === p ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, t ?? "");
|
|
437
437
|
}
|
|
438
438
|
}
|
|
439
|
-
class Et extends
|
|
439
|
+
class Et extends M {
|
|
440
440
|
constructor() {
|
|
441
441
|
super(...arguments), this.type = 3;
|
|
442
442
|
}
|
|
@@ -444,7 +444,7 @@ class Et extends k {
|
|
|
444
444
|
this.element[this.name] = t === p ? void 0 : t;
|
|
445
445
|
}
|
|
446
446
|
}
|
|
447
|
-
class St extends
|
|
447
|
+
class St extends M {
|
|
448
448
|
constructor() {
|
|
449
449
|
super(...arguments), this.type = 4;
|
|
450
450
|
}
|
|
@@ -452,7 +452,7 @@ class St extends k {
|
|
|
452
452
|
this.element.toggleAttribute(this.name, !!t && t !== p);
|
|
453
453
|
}
|
|
454
454
|
}
|
|
455
|
-
class wt extends
|
|
455
|
+
class wt extends M {
|
|
456
456
|
constructor(t, e, s, r, n) {
|
|
457
457
|
super(t, e, s, r, n), this.type = 5;
|
|
458
458
|
}
|
|
@@ -526,10 +526,10 @@ function Tt(i) {
|
|
|
526
526
|
api: _(v, i),
|
|
527
527
|
listActiveAlerts: _(Ot, i),
|
|
528
528
|
getActiveAlert: _(Nt, i),
|
|
529
|
-
listAlerts: _(
|
|
530
|
-
getAlert: _(
|
|
531
|
-
sendAlert: _(
|
|
532
|
-
cancelAlert: _(
|
|
529
|
+
listAlerts: _(kt, i),
|
|
530
|
+
getAlert: _(Ht, i),
|
|
531
|
+
sendAlert: _(It, i),
|
|
532
|
+
cancelAlert: _(Mt, i)
|
|
533
533
|
};
|
|
534
534
|
}
|
|
535
535
|
function Ot(i) {
|
|
@@ -540,19 +540,19 @@ 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 kt(i) {
|
|
544
544
|
return v(i, "/v1/alerts");
|
|
545
545
|
}
|
|
546
|
-
function
|
|
546
|
+
function Ht(i, t) {
|
|
547
547
|
return v(i, `/v1/alerts/${t}`);
|
|
548
548
|
}
|
|
549
|
-
function
|
|
549
|
+
function It(i, t) {
|
|
550
550
|
return v(i, "/v1/alerts", {
|
|
551
551
|
method: "POST",
|
|
552
552
|
body: t
|
|
553
553
|
});
|
|
554
554
|
}
|
|
555
|
-
function
|
|
555
|
+
function Mt(i, t) {
|
|
556
556
|
return v(i, `/v1/alerts/${t}`, {
|
|
557
557
|
method: "DELETE"
|
|
558
558
|
});
|
|
@@ -583,11 +583,11 @@ async function v(i, t, e) {
|
|
|
583
583
|
}
|
|
584
584
|
const Rt = {
|
|
585
585
|
lg: 1366
|
|
586
|
-
},
|
|
586
|
+
}, zt = "https://api.wral.com/alerts/v1/active/alerts", Lt = "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) => {
|
|
587
587
|
if (!i) return null;
|
|
588
588
|
const t = i.url || i.href || "", e = i.title || i.headline || "";
|
|
589
|
-
if (!
|
|
590
|
-
const s = String(i.topic || "").trim(), r = s.toLowerCase(), n = i.caption || s || "Alert", o = i.image || i.imageUrl || i.image_url ||
|
|
589
|
+
if (!e) return null;
|
|
590
|
+
const s = String(i.topic || "").trim(), r = s.toLowerCase(), n = i.caption || s || "Alert", o = i.image || i.imageUrl || i.image_url || Lt;
|
|
591
591
|
return {
|
|
592
592
|
url: t,
|
|
593
593
|
title: e,
|
|
@@ -620,7 +620,7 @@ class ot extends C {
|
|
|
620
620
|
refreshInterval: { type: Number, attribute: "refresh-interval" }
|
|
621
621
|
};
|
|
622
622
|
constructor() {
|
|
623
|
-
super(), this.api =
|
|
623
|
+
super(), this.api = zt, this.items = [], this.loading = !1, this.error = "", this.refreshInterval = 0, this._refreshId = null;
|
|
624
624
|
}
|
|
625
625
|
static styles = lt`
|
|
626
626
|
:host {
|
|
@@ -723,6 +723,12 @@ class ot extends C {
|
|
|
723
723
|
a.title:focus-visible {
|
|
724
724
|
text-decoration: underline;
|
|
725
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
|
+
}
|
|
726
732
|
.body {
|
|
727
733
|
margin: 0;
|
|
728
734
|
color: #323232;
|
|
@@ -801,7 +807,7 @@ class ot extends C {
|
|
|
801
807
|
render() {
|
|
802
808
|
const { items: t, loading: e, error: s } = this, r = (n, o) => {
|
|
803
809
|
const c = Bt(n.effectiveFrom), a = String(n.topic || "").trim().toLowerCase();
|
|
804
|
-
return
|
|
810
|
+
return f`
|
|
805
811
|
<li class="alert" data-index=${o} aria-label="Site Alert">
|
|
806
812
|
<div class="thumb">
|
|
807
813
|
<img
|
|
@@ -809,37 +815,40 @@ class ot extends C {
|
|
|
809
815
|
alt=${n.title}
|
|
810
816
|
loading="lazy"
|
|
811
817
|
>
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
818
|
+
</div>
|
|
819
|
+
<div class="alert-body">
|
|
820
|
+
<div class="alert-header">
|
|
821
|
+
<div class="label ${a}">
|
|
822
|
+
${jt(n.caption)}
|
|
823
|
+
</div>
|
|
824
|
+
${c ? f`
|
|
825
|
+
<span class="date">
|
|
826
|
+
${c}
|
|
827
|
+
</span>
|
|
828
|
+
` : ""}
|
|
817
829
|
</div>
|
|
818
|
-
${
|
|
819
|
-
<
|
|
820
|
-
|
|
821
|
-
</
|
|
822
|
-
`
|
|
830
|
+
${n.url ? f`
|
|
831
|
+
<a class="title" href=${n.url}>${n.body || n.title}</a>
|
|
832
|
+
` : f`
|
|
833
|
+
<div class="title no-link">${n.body || n.title}</div>
|
|
834
|
+
`}
|
|
823
835
|
</div>
|
|
824
|
-
|
|
825
|
-
${n.body ? $`<p class="body">${n.body}</p>` : ""}
|
|
826
|
-
</div>
|
|
827
|
-
</li>
|
|
836
|
+
</li>
|
|
828
837
|
`;
|
|
829
838
|
};
|
|
830
|
-
return
|
|
839
|
+
return f`
|
|
831
840
|
<div class="wrapper" role="region" aria-live="polite">
|
|
832
841
|
<div class="heading">
|
|
833
842
|
<span>Active Alerts</span>
|
|
834
|
-
${e ?
|
|
843
|
+
${e ? f`<span class="pill">Loading…</span>` : ""}
|
|
835
844
|
</div>
|
|
836
845
|
|
|
837
|
-
${s ?
|
|
838
|
-
${!s && !e && !t.length ?
|
|
846
|
+
${s ? f`<div class="status error">${s}</div>` : ""}
|
|
847
|
+
${!s && !e && !t.length ? f`
|
|
839
848
|
<div class="empty">No active alerts right now.</div>
|
|
840
849
|
` : ""}
|
|
841
850
|
|
|
842
|
-
${t.length ?
|
|
851
|
+
${t.length ? f`
|
|
843
852
|
<ul class="list">
|
|
844
853
|
${t.map(r)}
|
|
845
854
|
</ul>
|
package/dist/index.mjs
CHANGED
|
@@ -2,25 +2,25 @@ import { LitElement as d, css as m, html as i } from "lit";
|
|
|
2
2
|
import { createClient as f } from "@wral/sdk-alerts/v1";
|
|
3
3
|
const p = {
|
|
4
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 = (
|
|
6
|
-
if (!
|
|
7
|
-
const
|
|
8
|
-
if (!
|
|
9
|
-
const a = String(
|
|
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 = (e) => String(e || "Alert").replace(/[^\p{L}\p{N}]/gu, " ").replace(/\s+/g, " ").trim() || "Alert", v = (e) => {
|
|
6
|
+
if (!e) return null;
|
|
7
|
+
const t = e.url || e.href || "", s = e.title || e.headline || "";
|
|
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 || g;
|
|
10
10
|
return {
|
|
11
|
-
url:
|
|
11
|
+
url: t,
|
|
12
12
|
title: s,
|
|
13
13
|
topic: l || a,
|
|
14
14
|
caption: r,
|
|
15
15
|
image: n,
|
|
16
|
-
body:
|
|
17
|
-
effectiveFrom:
|
|
16
|
+
body: e.body || e.summary || "",
|
|
17
|
+
effectiveFrom: e.effectiveFrom || e.effective_from || ""
|
|
18
18
|
};
|
|
19
|
-
},
|
|
20
|
-
if (!
|
|
19
|
+
}, b = (e) => {
|
|
20
|
+
if (!e) return "";
|
|
21
21
|
try {
|
|
22
|
-
const
|
|
23
|
-
return Number.isNaN(
|
|
22
|
+
const t = new Date(e);
|
|
23
|
+
return Number.isNaN(t.getTime()) ? "" : t.toLocaleString(void 0, {
|
|
24
24
|
month: "short",
|
|
25
25
|
day: "numeric",
|
|
26
26
|
hour: "numeric",
|
|
@@ -142,6 +142,12 @@ class y extends d {
|
|
|
142
142
|
a.title:focus-visible {
|
|
143
143
|
text-decoration: underline;
|
|
144
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
|
+
}
|
|
145
151
|
.body {
|
|
146
152
|
margin: 0;
|
|
147
153
|
color: #323232;
|
|
@@ -188,8 +194,8 @@ class y extends d {
|
|
|
188
194
|
disconnectedCallback() {
|
|
189
195
|
super.disconnectedCallback(), this._clearInterval();
|
|
190
196
|
}
|
|
191
|
-
updated(
|
|
192
|
-
|
|
197
|
+
updated(t) {
|
|
198
|
+
t.has("api") && t.get("api") !== this.api && this.load(), t.has("refreshInterval") && this._setupInterval();
|
|
193
199
|
}
|
|
194
200
|
async fetchActiveAlerts() {
|
|
195
201
|
return f({
|
|
@@ -200,10 +206,10 @@ class y extends d {
|
|
|
200
206
|
if (this.api) {
|
|
201
207
|
this.loading = !0, this.error = "";
|
|
202
208
|
try {
|
|
203
|
-
const
|
|
204
|
-
this.items = (
|
|
205
|
-
} catch (
|
|
206
|
-
console.error("[wral-active-alerts]",
|
|
209
|
+
const t = await this.fetchActiveAlerts();
|
|
210
|
+
this.items = (t?.items || []).map(v).filter(Boolean);
|
|
211
|
+
} catch (t) {
|
|
212
|
+
console.error("[wral-active-alerts]", t), this.items = [], this.error = "Unable to load active alerts.";
|
|
207
213
|
} finally {
|
|
208
214
|
this.loading = !1;
|
|
209
215
|
}
|
|
@@ -211,15 +217,15 @@ class y extends d {
|
|
|
211
217
|
}
|
|
212
218
|
_setupInterval() {
|
|
213
219
|
this._clearInterval();
|
|
214
|
-
const
|
|
215
|
-
|
|
220
|
+
const t = Number(this.refreshInterval) || 0;
|
|
221
|
+
t > 0 && (this._refreshId = globalThis.setInterval(() => this.load(), t));
|
|
216
222
|
}
|
|
217
223
|
_clearInterval() {
|
|
218
224
|
this._refreshId && (globalThis.clearInterval(this._refreshId), this._refreshId = null);
|
|
219
225
|
}
|
|
220
226
|
render() {
|
|
221
|
-
const { items:
|
|
222
|
-
const o =
|
|
227
|
+
const { items: t, loading: s, error: a } = this, l = (r, n) => {
|
|
228
|
+
const o = b(r.effectiveFrom), c = String(r.topic || "").trim().toLowerCase();
|
|
223
229
|
return i`
|
|
224
230
|
<li class="alert" data-index=${n} aria-label="Site Alert">
|
|
225
231
|
<div class="thumb">
|
|
@@ -228,22 +234,25 @@ class y extends d {
|
|
|
228
234
|
alt=${r.title}
|
|
229
235
|
loading="lazy"
|
|
230
236
|
>
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
237
|
+
</div>
|
|
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
|
+
` : ""}
|
|
236
248
|
</div>
|
|
237
|
-
${
|
|
238
|
-
<
|
|
239
|
-
|
|
240
|
-
</
|
|
241
|
-
`
|
|
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
|
+
`}
|
|
242
254
|
</div>
|
|
243
|
-
|
|
244
|
-
${r.body ? i`<p class="body">${r.body}</p>` : ""}
|
|
245
|
-
</div>
|
|
246
|
-
</li>
|
|
255
|
+
</li>
|
|
247
256
|
`;
|
|
248
257
|
};
|
|
249
258
|
return i`
|
|
@@ -254,13 +263,13 @@ class y extends d {
|
|
|
254
263
|
</div>
|
|
255
264
|
|
|
256
265
|
${a ? i`<div class="status error">${a}</div>` : ""}
|
|
257
|
-
${!a && !s && !
|
|
266
|
+
${!a && !s && !t.length ? i`
|
|
258
267
|
<div class="empty">No active alerts right now.</div>
|
|
259
268
|
` : ""}
|
|
260
269
|
|
|
261
|
-
${
|
|
270
|
+
${t.length ? i`
|
|
262
271
|
<ul class="list">
|
|
263
|
-
${
|
|
272
|
+
${t.map(l)}
|
|
264
273
|
</ul>
|
|
265
274
|
` : ""}
|
|
266
275
|
</div>
|
|
@@ -270,6 +279,6 @@ class y extends d {
|
|
|
270
279
|
globalThis?.customElements && !globalThis.customElements.get("wral-active-alerts") && globalThis.customElements.define("wral-active-alerts", y);
|
|
271
280
|
export {
|
|
272
281
|
y as W,
|
|
273
|
-
|
|
282
|
+
v as n,
|
|
274
283
|
u as s
|
|
275
284
|
};
|