@wral/active-alerts 0.1.4 → 0.2.1

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
@@ -1,4 +1,4 @@
1
- import { W as t } from "./wral-active-alerts-CSZAUUIB.js";
1
+ import { W as t } from "./wral-active-alerts-Dd9mTg2z.js";
2
2
  function i() {
3
3
  const e = globalThis?.customElements;
4
4
  e && (e.get("wral-active-alerts") || e.define("wral-active-alerts", t));
@@ -3,7 +3,7 @@
3
3
  * Copyright 2019 Google LLC
4
4
  * SPDX-License-Identifier: BSD-3-Clause
5
5
  */
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();
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.");
@@ -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 = H.litNonce;
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
38
  }, q = L ? (i) => i : (i) => i instanceof CSSStyleSheet ? ((t) => {
@@ -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, z = { toAttribute(i, t) {
48
+ const { is: ct, defineProperty: dt, getOwnPropertyDescriptor: pt, getOwnPropertyNames: ut, getOwnPropertySymbols: ft, getPrototypeOf: $t } = Object, I = globalThis, F = I.trustedTypes, mt = F ? F.emptyScript : "", gt = I.reactiveElementPolyfillSupport, x = (i, t) => i, z = { toAttribute(i, t) {
49
49
  switch (t) {
50
50
  case Boolean:
51
51
  i = i ? mt : null;
@@ -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"), M.litPropertyMetadata ??= /* @__PURE__ */ new WeakMap();
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);
@@ -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 }), (M.reactiveElementVersions ??= []).push("2.1.1");
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, 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}>`, y = document, P = () => y.createComment(""), U = (i) => i === null || typeof i != "object" && typeof i != "function", B = Array.isArray, At = (i) => B(i) || typeof i?.[Symbol.iterator] == "function", R = `[
265
+ const D = globalThis, H = D.trustedTypes, J = H ? H.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, yt = (i) => (t, ...e) => ({ _$litType$: i, strings: t, values: e }), $ = yt(1), E = Symbol.for("lit-noChange"), p = Symbol.for("lit-nothing"), Y = /* @__PURE__ */ new WeakMap(), A = y.createTreeWalker(y, 129);
267
+ \f\r"'\`<>=]|("|')|))|$)`, "g"), Q = /'/g, X = /"/g, rt = /^(?:script|style|textarea|title)$/i, At = (i) => (t, ...e) => ({ _$litType$: i, strings: t, values: e }), u = 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;
@@ -274,10 +274,10 @@ const vt = (i, t) => {
274
274
  let r, n = t === 2 ? "<svg>" : t === 3 ? "<math>" : "", o = w;
275
275
  for (let c = 0; c < e; c++) {
276
276
  const a = i[c];
277
- let d, 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, 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 f = 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 + f) : a + m + (h === -2 ? c : f);
277
+ let d, l, h = -1, f = 0;
278
+ for (; f < a.length && (o.lastIndex = f, l = o.exec(a), l !== null); ) f = 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 $ = 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 + m + (h === -2 ? c : $);
281
281
  }
282
282
  return [nt(i, n + (i[e] || "<?>") + (t === 2 ? "</svg>" : t === 3 ? "</math>" : "")), s];
283
283
  };
@@ -287,22 +287,22 @@ 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), A.currentNode = this.el.content, e === 2 || e === 3) {
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 = A.nextNode()) !== null && a.length < c; ) {
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++], 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 : k }), r.removeAttribute(h);
297
+ const f = l[o++], $ = r.getAttribute(h).split(m), N = /([.?@])?(.*)/.exec(f);
298
+ a.push({ type: 1, index: n, name: N[2], strings: $, ctor: N[1] === "." ? Et : N[1] === "?" ? St : N[1] === "@" ? wt : M }), r.removeAttribute(h);
299
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(m), u = h.length - 1;
302
- if (u > 0) {
303
- r.textContent = I ? I.emptyScript : "";
304
- for (let f = 0; f < u; f++) r.append(h[f], P()), A.nextNode(), a.push({ type: 2, index: ++n });
305
- r.append(h[u], P());
301
+ const h = r.textContent.split(m), f = h.length - 1;
302
+ if (f > 0) {
303
+ r.textContent = H ? H.emptyScript : "";
304
+ for (let $ = 0; $ < f; $++) r.append(h[$], P()), y.nextNode(), a.push({ type: 2, index: ++n });
305
+ r.append(h[f], P());
306
306
  }
307
307
  }
308
308
  } else if (r.nodeType === 8) if (r.data === it) a.push({ type: 2, index: n });
@@ -314,7 +314,7 @@ class T {
314
314
  }
315
315
  }
316
316
  static createElement(t, e) {
317
- const s = y.createElement("template");
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 ?? y).importNode(e, !0);
339
- A.currentNode = r;
340
- let n = A.nextNode(), o = 0, c = 0, a = s[0];
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 = A.nextNode(), o++);
346
+ o !== a?.index && (n = y.nextNode(), o++);
347
347
  }
348
- return A.currentNode = y, r;
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) : At(t) ? this.k(t) : this._(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(y.createTextNode(t)), this._$AH = 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 k {
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 k {
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 k {
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 k {
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: _(Ht, i),
530
- getAlert: _(It, i),
531
- sendAlert: _(Mt, i),
532
- cancelAlert: _(kt, i)
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 Ht(i) {
543
+ function kt(i) {
544
544
  return v(i, "/v1/alerts");
545
545
  }
546
- function It(i, t) {
546
+ function Ht(i, t) {
547
547
  return v(i, `/v1/alerts/${t}`);
548
548
  }
549
- function Mt(i, t) {
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 kt(i, t) {
555
+ function Mt(i, t) {
556
556
  return v(i, `/v1/alerts/${t}`, {
557
557
  method: "DELETE"
558
558
  });
@@ -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 = "https://api.wral.com/alerts/v1/active/alerts", zt = "https://assets.wral.com/a1cc0e86-adab-48e9-bd80-703cd2c56aff?w=1200&h=630", Lt = (i) => String(i || "Alert").replace(/[^\p{L}\p{N}]/gu, " ").replace(/\s+/g, " ").trim() || "Alert", jt = (i) => {
584
+ const Rt = {
585
+ lg: 1366
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) => {
585
587
  if (!i) return null;
586
588
  const t = i.url || i.href || "", e = i.title || i.headline || "";
587
- if (!t || !e) return null;
588
- const s = i.topic || "", r = i.caption || s || "Alert", n = i.image || i.imageUrl || i.image_url || zt;
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;
589
591
  return {
590
592
  url: t,
591
593
  title: e,
592
- topic: s,
593
- caption: r,
594
- image: n,
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
- }, Dt = (i) => {
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 = Rt, this.items = [], this.loading = !1, this.error = "", this.refreshInterval = 0, this._refreshId = null;
623
+ super(), this.api = zt, 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: 1040px;
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.35rem;
704
- border-radius: 6px;
705
+ padding: 0.125rem 0.1875rem 0.05rem;
706
+ border-radius: 4px;
705
707
  text-transform: uppercase;
706
- background-color: #c15800;
708
+ background-color: #daa520; /* default (gold) */
707
709
  letter-spacing: .03em;
708
710
  }
709
711
  .label.recommended-story {
@@ -721,6 +723,12 @@ class ot extends C {
721
723
  a.title:focus-visible {
722
724
  text-decoration: underline;
723
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
+ }
724
732
  .body {
725
733
  margin: 0;
726
734
  color: #323232;
@@ -780,7 +788,7 @@ class ot extends C {
780
788
  this.loading = !0, this.error = "";
781
789
  try {
782
790
  const t = await this.fetchActiveAlerts();
783
- this.items = (t?.items || []).map(jt).filter(Boolean);
791
+ this.items = (t?.items || []).map(Dt).filter(Boolean);
784
792
  } catch (t) {
785
793
  console.error("[wral-active-alerts]", t), this.items = [], this.error = "Unable to load active alerts.";
786
794
  } finally {
@@ -798,8 +806,8 @@ class ot extends C {
798
806
  }
799
807
  render() {
800
808
  const { items: t, loading: e, error: s } = this, r = (n, o) => {
801
- const c = Dt(n.effectiveFrom);
802
- return $`
809
+ const c = Bt(n.effectiveFrom), a = String(n.topic || "").trim().toLowerCase();
810
+ return u`
803
811
  <li class="alert" data-index=${o} aria-label="Site Alert">
804
812
  <div class="thumb">
805
813
  <img
@@ -807,37 +815,41 @@ class ot extends C {
807
815
  alt=${n.title}
808
816
  loading="lazy"
809
817
  >
810
- </div>
811
- <div class="alert-body">
812
- <div class="alert-header">
813
- <div class="label ${n.topic}">
814
- ${Lt(n.caption)}
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 ? u`
825
+ <span class="date">
826
+ ${c}
827
+ </span>
828
+ ` : ""}
815
829
  </div>
816
- ${c ? $`
817
- <span class="date">
818
- ${c}
819
- </span>
820
- ` : ""}
830
+ ${n.url ? u`
831
+ <a class="title" href=${n.url}>${n.title}</a>
832
+ ` : u`
833
+ <div class="title no-link">${n.title}</div>
834
+ `}
835
+ ${n.body ? u`<p class="body">${n.body}</p>` : ""}
821
836
  </div>
822
- <a class="title" href=${n.url}>${n.title}</a>
823
- ${n.body ? $`<p class="body">${n.body}</p>` : ""}
824
- </div>
825
- </li>
837
+ </li>
826
838
  `;
827
839
  };
828
- return $`
840
+ return u`
829
841
  <div class="wrapper" role="region" aria-live="polite">
830
842
  <div class="heading">
831
843
  <span>Active Alerts</span>
832
- ${e ? $`<span class="pill">Loading…</span>` : ""}
844
+ ${e ? u`<span class="pill">Loading…</span>` : ""}
833
845
  </div>
834
846
 
835
- ${s ? $`<div class="status error">${s}</div>` : ""}
836
- ${!s && !e && !t.length ? $`
847
+ ${s ? u`<div class="status error">${s}</div>` : ""}
848
+ ${!s && !e && !t.length ? u`
837
849
  <div class="empty">No active alerts right now.</div>
838
850
  ` : ""}
839
851
 
840
- ${t.length ? $`
852
+ ${t.length ? u`
841
853
  <ul class="list">
842
854
  ${t.map(r)}
843
855
  </ul>
@@ -847,11 +859,11 @@ class ot extends C {
847
859
  }
848
860
  }
849
861
  globalThis?.customElements && !globalThis.customElements.get("wral-active-alerts") && globalThis.customElements.define("wral-active-alerts", ot);
850
- function Bt() {
862
+ function Wt() {
851
863
  const i = globalThis?.customElements;
852
864
  i && (i.get("wral-active-alerts") || i.define("wral-active-alerts", ot));
853
865
  }
854
- typeof window < "u" && globalThis.customElements && Bt();
866
+ typeof window < "u" && globalThis.customElements && Wt();
855
867
  export {
856
- Bt as defineAll
868
+ Wt as defineAll
857
869
  };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { W as r, n as s, s as l } from "./wral-active-alerts-CSZAUUIB.js";
1
+ import { W as r, n as s, s as l } from "./wral-active-alerts-Dd9mTg2z.js";
2
2
  export {
3
3
  r as WralActiveAlerts,
4
4
  s as normalizeAlert,
@@ -1,24 +1,26 @@
1
- import { LitElement as c, css as d, html as i } from "lit";
2
- import { createClient as m } from "@wral/sdk-alerts/v1";
3
- const f = "https://api.wral.com/alerts/v1/active/alerts", p = "https://assets.wral.com/a1cc0e86-adab-48e9-bd80-703cd2c56aff?w=1200&h=630", h = (t) => String(t || "Alert").replace(/[^\p{L}\p{N}]/gu, " ").replace(/\s+/g, " ").trim() || "Alert", g = (t) => {
4
- if (!t) return null;
5
- const e = t.url || t.href || "", s = t.title || t.headline || "";
6
- if (!e || !s) return null;
7
- const a = t.topic || "", l = t.caption || a || "Alert", r = t.image || t.imageUrl || t.image_url || p;
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 = (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;
8
10
  return {
9
- url: e,
11
+ url: t,
10
12
  title: s,
11
- topic: a,
12
- caption: l,
13
- image: r,
14
- body: t.body || t.summary || "",
15
- effectiveFrom: t.effectiveFrom || t.effective_from || ""
13
+ topic: l || a,
14
+ caption: r,
15
+ image: n,
16
+ body: e.body || e.summary || "",
17
+ effectiveFrom: e.effectiveFrom || e.effective_from || ""
16
18
  };
17
- }, u = (t) => {
18
- if (!t) return "";
19
+ }, b = (e) => {
20
+ if (!e) return "";
19
21
  try {
20
- const e = new Date(t);
21
- return Number.isNaN(e.getTime()) ? "" : e.toLocaleString(void 0, {
22
+ const t = new Date(e);
23
+ return Number.isNaN(t.getTime()) ? "" : t.toLocaleString(void 0, {
22
24
  month: "short",
23
25
  day: "numeric",
24
26
  hour: "numeric",
@@ -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 b extends c {
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 = f, this.items = [], this.loading = !1, this.error = "", this.refreshInterval = 0, this._refreshId = null;
42
+ super(), this.api = h, this.items = [], this.loading = !1, this.error = "", this.refreshInterval = 0, this._refreshId = null;
41
43
  }
42
- static styles = d`
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: 1040px;
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.35rem;
123
- border-radius: 6px;
124
+ padding: 0.125rem 0.1875rem 0.05rem;
125
+ border-radius: 4px;
124
126
  text-transform: uppercase;
125
- background-color: #c15800;
127
+ background-color: #daa520; /* default (gold) */
126
128
  letter-spacing: .03em;
127
129
  }
128
130
  .label.recommended-story {
@@ -140,6 +142,12 @@ class b extends c {
140
142
  a.title:focus-visible {
141
143
  text-decoration: underline;
142
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
+ }
143
151
  .body {
144
152
  margin: 0;
145
153
  color: #323232;
@@ -186,11 +194,11 @@ class b extends c {
186
194
  disconnectedCallback() {
187
195
  super.disconnectedCallback(), this._clearInterval();
188
196
  }
189
- updated(e) {
190
- e.has("api") && e.get("api") !== this.api && this.load(), e.has("refreshInterval") && this._setupInterval();
197
+ updated(t) {
198
+ t.has("api") && t.get("api") !== this.api && this.load(), t.has("refreshInterval") && this._setupInterval();
191
199
  }
192
200
  async fetchActiveAlerts() {
193
- return m({
201
+ return f({
194
202
  baseUrl: this.api.replace(/v1\/.*$/, "")
195
203
  }).listActiveAlerts();
196
204
  }
@@ -198,10 +206,10 @@ class b extends c {
198
206
  if (this.api) {
199
207
  this.loading = !0, this.error = "";
200
208
  try {
201
- const e = await this.fetchActiveAlerts();
202
- this.items = (e?.items || []).map(g).filter(Boolean);
203
- } catch (e) {
204
- console.error("[wral-active-alerts]", e), this.items = [], this.error = "Unable to load 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.";
205
213
  } finally {
206
214
  this.loading = !1;
207
215
  }
@@ -209,39 +217,43 @@ class b extends c {
209
217
  }
210
218
  _setupInterval() {
211
219
  this._clearInterval();
212
- const e = Number(this.refreshInterval) || 0;
213
- e > 0 && (this._refreshId = globalThis.setInterval(() => this.load(), e));
220
+ const t = Number(this.refreshInterval) || 0;
221
+ t > 0 && (this._refreshId = globalThis.setInterval(() => this.load(), t));
214
222
  }
215
223
  _clearInterval() {
216
224
  this._refreshId && (globalThis.clearInterval(this._refreshId), this._refreshId = null);
217
225
  }
218
226
  render() {
219
- const { items: e, loading: s, error: a } = this, l = (r, o) => {
220
- const n = u(r.effectiveFrom);
227
+ const { items: t, loading: s, error: a } = this, l = (r, n) => {
228
+ const o = b(r.effectiveFrom), c = String(r.topic || "").trim().toLowerCase();
221
229
  return i`
222
- <li class="alert" data-index=${o} aria-label="Site Alert">
230
+ <li class="alert" data-index=${n} aria-label="Site Alert">
223
231
  <div class="thumb">
224
232
  <img
225
233
  src=${r.image}
226
234
  alt=${r.title}
227
235
  loading="lazy"
228
236
  >
229
- </div>
230
- <div class="alert-body">
231
- <div class="alert-header">
232
- <div class="label ${r.topic}">
233
- ${h(r.caption)}
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
+ ` : ""}
234
248
  </div>
235
- ${n ? i`
236
- <span class="date">
237
- ${n}
238
- </span>
239
- ` : ""}
249
+ ${r.url ? i`
250
+ <a class="title" href=${r.url}>${r.title}</a>
251
+ ` : i`
252
+ <div class="title no-link">${r.title}</div>
253
+ `}
254
+ ${r.body ? i`<p class="body">${r.body}</p>` : ""}
240
255
  </div>
241
- <a class="title" href=${r.url}>${r.title}</a>
242
- ${r.body ? i`<p class="body">${r.body}</p>` : ""}
243
- </div>
244
- </li>
256
+ </li>
245
257
  `;
246
258
  };
247
259
  return i`
@@ -252,22 +264,22 @@ class b extends c {
252
264
  </div>
253
265
 
254
266
  ${a ? i`<div class="status error">${a}</div>` : ""}
255
- ${!a && !s && !e.length ? i`
267
+ ${!a && !s && !t.length ? i`
256
268
  <div class="empty">No active alerts right now.</div>
257
269
  ` : ""}
258
270
 
259
- ${e.length ? i`
271
+ ${t.length ? i`
260
272
  <ul class="list">
261
- ${e.map(l)}
273
+ ${t.map(l)}
262
274
  </ul>
263
275
  ` : ""}
264
276
  </div>
265
277
  `;
266
278
  }
267
279
  }
268
- globalThis?.customElements && !globalThis.customElements.get("wral-active-alerts") && globalThis.customElements.define("wral-active-alerts", b);
280
+ globalThis?.customElements && !globalThis.customElements.get("wral-active-alerts") && globalThis.customElements.define("wral-active-alerts", y);
269
281
  export {
270
- b as W,
271
- g as n,
272
- h as s
282
+ y as W,
283
+ v as n,
284
+ u as s
273
285
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wral/active-alerts",
3
- "version": "0.1.4",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "description": "Lit web component for rendering the current set of active WRAL alerts.",
6
6
  "author": "Dominick Jones <djones@wral.com>",