@panda-lingo/goldendict 0.1.3 → 0.1.4

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/index.js CHANGED
@@ -1,11 +1,11 @@
1
- class q extends Error {
1
+ class M extends Error {
2
2
  status;
3
3
  body;
4
4
  constructor(e, o, t) {
5
5
  super(e), this.name = "DictionaryApiError", this.status = o, this.body = t;
6
6
  }
7
7
  }
8
- function L(i) {
8
+ function B(i) {
9
9
  const e = i.trim() || "/api/v1";
10
10
  return e.length > 1 ? e.replace(/\/+$/, "") : e;
11
11
  }
@@ -25,7 +25,7 @@ function y(i) {
25
25
  ...i.wordCount !== void 0 ? { wordCount: i.wordCount } : {}
26
26
  };
27
27
  }
28
- async function B(i) {
28
+ async function $(i) {
29
29
  const e = await i.text();
30
30
  if (e)
31
31
  try {
@@ -40,7 +40,7 @@ class v {
40
40
  headers;
41
41
  credentials;
42
42
  constructor(e = {}) {
43
- this.baseUrl = L(e.baseUrl ?? "/api/v1");
43
+ this.baseUrl = B(e.baseUrl ?? "/api/v1");
44
44
  const o = e.fetch ?? globalThis.fetch;
45
45
  if (!o)
46
46
  throw new TypeError("A fetch implementation is required");
@@ -94,12 +94,12 @@ class v {
94
94
  ...this.headers,
95
95
  ...o.headers
96
96
  }
97
- }), n = await B(t);
97
+ }), n = await $(t);
98
98
  if (!t.ok) {
99
99
  let a = t.statusText;
100
100
  throw typeof n == "object" && n && ("message" in n ? a = String(n.message) : "error" in n && typeof n.error == "object" && n.error && "message" in n.error && (a = String(
101
101
  n.error.message
102
- ))), new q(
102
+ ))), new M(
103
103
  a || `Dictionary request failed (${t.status})`,
104
104
  t.status,
105
105
  n
@@ -108,7 +108,7 @@ class v {
108
108
  return n;
109
109
  }
110
110
  }
111
- const M = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
111
+ const U = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
112
112
  <!-- Created with Inkscape (http://www.inkscape.org/) -->
113
113
 
114
114
  <svg
@@ -154,7 +154,7 @@ const M = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
154
154
  sodipodi:nodetypes="cccc" />
155
155
  </g>
156
156
  </svg>
157
- `, U = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QA/4ePzL8AAAAHdElNRQfmAxMKDTHgIis/AAAAwUlEQVQoz33RsUtCcRTF8U+vJ8/RCAKHdEoc+isachBcMhranQQXt/YIGmxrLAgRac/JFsP+jVqaHVvkuTy0V/08dzzfC/eew2+1FWxRz1KCG42/ZuxeKpWgaeYub++ZStcAsRcddgwdgCPVDC1qOHat7F2dz2xvMwluXeDBWQgomeDSIAp8s1DEh8PIdqUhoOQbFV8h4MojTsxjb9mbNZW13bIwtu9U72dQr7mgeNIPR10z9CwKlzXStfv/eef5uldwrDr7rieveQAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMi0wMy0xOVQxMDoxMzo0OSswMDowMH0jItoAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjItMDMtMTlUMTA6MTM6NDkrMDA6MDAMfppmAAAAAElFTkSuQmCC", $ = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
157
+ `, R = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QA/4ePzL8AAAAHdElNRQfmAxMKDTHgIis/AAAAwUlEQVQoz33RsUtCcRTF8U+vJ8/RCAKHdEoc+isachBcMhranQQXt/YIGmxrLAgRac/JFsP+jVqaHVvkuTy0V/08dzzfC/eew2+1FWxRz1KCG42/ZuxeKpWgaeYub++ZStcAsRcddgwdgCPVDC1qOHat7F2dz2xvMwluXeDBWQgomeDSIAp8s1DEh8PIdqUhoOQbFV8h4MojTsxjb9mbNZW13bIwtu9U72dQr7mgeNIPR10z9CwKlzXStfv/eef5uldwrDr7rieveQAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMi0wMy0xOVQxMDoxMzo0OSswMDowMH0jItoAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjItMDMtMTlUMTA6MTM6NDkrMDA6MDAMfppmAAAAAElFTkSuQmCC", F = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
158
158
  <!-- Created with Inkscape (http://www.inkscape.org/) -->
159
159
 
160
160
  <svg
@@ -196,7 +196,7 @@ const M = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
196
196
  d="m 9.8109427,14.803704 8.9999993,-8.9999986 -17.9999995,2e-7 z m 0,-4.225584 -4.7744158,-4.7744144 9.5488291,-2e-7 z"
197
197
  id="rect1"
198
198
  sodipodi:nodetypes="cccccccc" /></g></svg>
199
- `, F = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
199
+ `, P = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
200
200
  <!-- Created with Inkscape (http://www.inkscape.org/) -->
201
201
 
202
202
  <svg
@@ -243,7 +243,7 @@ const M = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
243
243
  sodipodi:nodetypes="cccccccc" />
244
244
  </g>
245
245
  </svg>
246
- `, P = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
246
+ `, G = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
247
247
  <svg
248
248
  width="24.000002"
249
249
  height="24"
@@ -311,7 +311,7 @@ const M = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
311
311
  x="1.1215118e-09"
312
312
  y="4.9718442"
313
313
  ry="0.64957041" /></svg>
314
- `, R = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAATrAAAE6wHYKlsNAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAcRJREFUOI2lkztvE0EQgL8Z7/rB2T5fCixhQQc00FAjJCRkiTYV/JH0adIgfgJVGn4CKRBUSIjCHYiOBimK7KA4ORw/dofC3Ck2dhpGGu1r5pvZmV0xM/5HXDEZDAbf2u12BkiM0UIImBlmRoyxHBeLBaPRaNzv9++tAJIkyVS1673HzBCRUtfFzEo/d/VAVRERzvf2uDw6AqB6eMhlt1va9Hq9FWgJiDEiIqgqcTwmnp4CUPeearu9EmRjDYp7qiqVNEV3dgCYx8hlniMimBlZlm0GFN0QERoHB7j9/bIGVUDiHCrVfzLQqwDvPSLCZDIhz3MuLi6YTye4eY58fkOnUbkeUERMkoRWq0WaptRqDaYfXvPr3StmP75cX4PZbIb3HoDx6TmttImveZoPn9N+0KfWvbsdYGY45xARvn76zvu3H8m6GS/2dpnefLRsb4Bb2wAhBJxbLoc/hwCcDc9QqVCvuzLy+uPa2IUnu4+p36hz5/5tGkmdxWKBc45Op0MIYXsNClAzTXj28imquqKFzUbA8fHxbzMbi0glhKBmpsuEREQkqmpU1Sgi8eTkJC/8ZNN3FhEHNIHG360pkJvZdN32D0SOwDehr1HXAAAAAElFTkSuQmCC", G = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
314
+ `, N = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAATrAAAE6wHYKlsNAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAcRJREFUOI2lkztvE0EQgL8Z7/rB2T5fCixhQQc00FAjJCRkiTYV/JH0adIgfgJVGn4CKRBUSIjCHYiOBimK7KA4ORw/dofC3Ck2dhpGGu1r5pvZmV0xM/5HXDEZDAbf2u12BkiM0UIImBlmRoyxHBeLBaPRaNzv9++tAJIkyVS1673HzBCRUtfFzEo/d/VAVRERzvf2uDw6AqB6eMhlt1va9Hq9FWgJiDEiIqgqcTwmnp4CUPeearu9EmRjDYp7qiqVNEV3dgCYx8hlniMimBlZlm0GFN0QERoHB7j9/bIGVUDiHCrVfzLQqwDvPSLCZDIhz3MuLi6YTye4eY58fkOnUbkeUERMkoRWq0WaptRqDaYfXvPr3StmP75cX4PZbIb3HoDx6TmttImveZoPn9N+0KfWvbsdYGY45xARvn76zvu3H8m6GS/2dpnefLRsb4Bb2wAhBJxbLoc/hwCcDc9QqVCvuzLy+uPa2IUnu4+p36hz5/5tGkmdxWKBc45Op0MIYXsNClAzTXj28imquqKFzUbA8fHxbzMbi0glhKBmpsuEREQkqmpU1Sgi8eTkJC/8ZNN3FhEHNIHG360pkJvZdN32D0SOwDehr1HXAAAAAElFTkSuQmCC", V = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
315
315
  <!-- Created with Inkscape (http://www.inkscape.org/) -->
316
316
 
317
317
  <svg
@@ -357,7 +357,7 @@ const M = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
357
357
  sodipodi:nodetypes="cccc" />
358
358
  </g>
359
359
  </svg>
360
- `, N = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
360
+ `, O = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
361
361
  <!-- Created with Inkscape (http://www.inkscape.org/) -->
362
362
 
363
363
  <svg
@@ -399,7 +399,7 @@ const M = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
399
399
  d="m 14.310942,9.9316324 -8.9999991,-8.9999982 2e-7,17.9999978 z m -4.225584,0 -4.7744149,4.7744156 -2e-7,-9.5488279 z"
400
400
  id="rect1"
401
401
  sodipodi:nodetypes="cccccccc" /></g></svg>
402
- `, O = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
402
+ `, H = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
403
403
  <!-- Created with Inkscape (http://www.inkscape.org/) -->
404
404
 
405
405
  <svg
@@ -446,7 +446,7 @@ const M = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
446
446
  sodipodi:nodetypes="cccccccc" />
447
447
  </g>
448
448
  </svg>
449
- `, V = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
449
+ `, W = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
450
450
  <svg
451
451
  width="24.000002"
452
452
  height="24"
@@ -515,7 +515,7 @@ const M = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
515
515
  x="1.1215118e-09"
516
516
  y="4.9718442"
517
517
  ry="0.64957041" /></svg>
518
- `, H = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
518
+ `, j = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
519
519
  <!-- Created with Inkscape (http://www.inkscape.org/) -->
520
520
 
521
521
  <svg
@@ -575,7 +575,7 @@ const M = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
575
575
  id="path2"
576
576
  style="fill:url(#radialGradient2)" />
577
577
  </svg>
578
- `, W = `<?xml version="1.0" encoding="UTF-8"?>
578
+ `, Z = `<?xml version="1.0" encoding="UTF-8"?>
579
579
  <!-- Created with Inkscape (http://www.inkscape.org/) -->
580
580
  <svg width="32" height="32" version="1.1" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
581
581
  <defs>
@@ -586,7 +586,7 @@ const M = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
586
586
  </defs>
587
587
  <path d="m3.7149 8.6551 24.57 1e-6 -12.286 14.69z" fill="url(#radialGradient2)" fill-rule="evenodd" stroke-width="3.7795"/>
588
588
  </svg>
589
- `, j = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
589
+ `, X = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
590
590
  <svg
591
591
  width="23.02533"
592
592
  height="24"
@@ -699,7 +699,7 @@ const M = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
699
699
  transform="matrix(0.71827705,0,0,0.71827705,-3.1349141,-8.3199121)"
700
700
  style="fill:url(#linearGradient9);fill-opacity:1;stroke:none" />
701
701
  </svg>
702
- `, Z = `<svg fill="none" stroke="white" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
702
+ `, Q = `<svg fill="none" stroke="white" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
703
703
  <defs>
704
704
  <linearGradient id="videoGrad" y2="100%">
705
705
  <stop stop-color="#FF5F6D" offset="0"/>
@@ -709,7 +709,7 @@ const M = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
709
709
  <rect x="2" y="5" width="20" height="14" rx="2" ry="2" fill="url(#videoGrad)" stroke="none"/>
710
710
  <polygon points="10 9 15 12 10 15" fill="#fff"/>
711
711
  </svg>
712
- `, Q = `<svg fill="none" stroke="white" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
712
+ `, K = `<svg fill="none" stroke="white" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" version="1.1" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
713
713
  <defs>
714
714
  <linearGradient id="warnGrad" y2="100%">
715
715
  <stop stop-color="#FF5F6D" offset="0"/>
@@ -725,27 +725,27 @@ function s(i) {
725
725
  return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(i)}`;
726
726
  }
727
727
  const u = {
728
- "arrow.svg": s(M),
729
- "audio.png": U,
730
- "collapse_article.svg": s(F),
731
- "collapse_article_hovered.svg": s($),
732
- "collapse_opt.svg": s(P),
733
- "document.png": R,
734
- "downarrow.svg": s(G),
735
- "expand_article.svg": s(O),
736
- "expand_article_hovered.svg": s(N),
737
- "expand_opt.svg": s(V),
738
- "old-arrow.svg": s(H),
739
- "old-downarrow.svg": s(W),
740
- "playsound.svg": s(j),
741
- "video.svg": s(Z),
742
- "warning.svg": s(Q)
728
+ "arrow.svg": s(U),
729
+ "audio.png": R,
730
+ "collapse_article.svg": s(P),
731
+ "collapse_article_hovered.svg": s(F),
732
+ "collapse_opt.svg": s(G),
733
+ "document.png": N,
734
+ "downarrow.svg": s(V),
735
+ "expand_article.svg": s(H),
736
+ "expand_article_hovered.svg": s(O),
737
+ "expand_opt.svg": s(W),
738
+ "old-arrow.svg": s(j),
739
+ "old-downarrow.svg": s(Z),
740
+ "playsound.svg": s(X),
741
+ "video.svg": s(Q),
742
+ "warning.svg": s(K)
743
743
  };
744
- function A(i) {
744
+ function S(i) {
745
745
  const e = /^qrc:\/{2,3}(?:icons\/)?([^?#]+)(?:[?#].*)?$/i.exec(i);
746
746
  return e?.[1] ? u[e[1]] : void 0;
747
747
  }
748
- function z(i) {
748
+ function A(i) {
749
749
  return i.replace(
750
750
  /qrc:\/{2,3}icons\/([a-z0-9_.-]+)/gi,
751
751
  (e, o) => u[o] ?? e
@@ -7883,19 +7883,19 @@ a:hover {
7883
7883
  code::selection {
7884
7884
  background: #333333;
7885
7885
  }
7886
- ` }, X = h["article-style.css"], K = h["article-style-print.css"], J = h["article-style-st-babylon.css"], Y = h["article-style-st-classic.css"], ee = h["article-style-st-lingoes-blue.css"], ie = h["article-style-st-lingoes.css"], te = h["article-style-st-lingvo.css"], oe = h["article-style-st-modern.css"], ne = {
7886
+ ` }, J = h["article-style.css"], Y = h["article-style-print.css"], ee = h["article-style-st-babylon.css"], ie = h["article-style-st-classic.css"], te = h["article-style-st-lingoes-blue.css"], oe = h["article-style-st-lingoes.css"], ne = h["article-style-st-lingvo.css"], re = h["article-style-st-modern.css"], ae = {
7887
7887
  default: "",
7888
- classic: Y,
7889
- modern: oe,
7890
- lingvo: te,
7891
- babylon: J,
7892
- lingoes: ie,
7893
- "lingoes-blue": ee
7894
- }, re = z(X), ae = z(K);
7895
- function de(i = "default") {
7896
- return z(ne[i]);
7897
- }
7898
- const le = `
7888
+ classic: ie,
7889
+ modern: re,
7890
+ lingvo: ne,
7891
+ babylon: ee,
7892
+ lingoes: oe,
7893
+ "lingoes-blue": te
7894
+ }, de = A(J), le = A(Y);
7895
+ function se(i = "default") {
7896
+ return A(ae[i]);
7897
+ }
7898
+ const ce = `
7899
7899
  :root {
7900
7900
  --gd-responsive-gutter: clamp(0.5rem, 2.5vw, 1rem);
7901
7901
  }
@@ -8021,13 +8021,13 @@ const le = `
8021
8021
  min-block-size: 2.75rem;
8022
8022
  }
8023
8023
  }
8024
- `, T = /* @__PURE__ */ new Set([
8024
+ `, E = /* @__PURE__ */ new Set([
8025
8025
  "bres",
8026
8026
  "qrcx",
8027
8027
  "gico",
8028
8028
  "gdau",
8029
8029
  "gdvideo"
8030
- ]), se = {
8030
+ ]), _ = "/api/v1", me = {
8031
8031
  gdlookup: "lookup",
8032
8032
  bword: "lookup",
8033
8033
  entry: "lookup",
@@ -8042,10 +8042,10 @@ const le = `
8042
8042
  gdinternal: "unsupported",
8043
8043
  ankicard: "unsupported",
8044
8044
  ankisearch: "unsupported"
8045
- }, ce = new Set(
8046
- Object.entries(se).filter(([, i]) => i === "unsupported").map(([i]) => i)
8045
+ }, pe = new Set(
8046
+ Object.entries(me).filter(([, i]) => i === "unsupported").map(([i]) => i)
8047
8047
  );
8048
- function f(i) {
8048
+ function w(i) {
8049
8049
  try {
8050
8050
  return decodeURIComponent(i);
8051
8051
  } catch {
@@ -8055,43 +8055,47 @@ function f(i) {
8055
8055
  function I(i, e) {
8056
8056
  return `${i.replace(/\/+$/, "")}/${e.replace(/^\/+/, "")}`;
8057
8057
  }
8058
- function me(i) {
8059
- return i.pathname.replace(/^\/+/, "").split("/").map((e) => encodeURIComponent(f(e))).join("/");
8058
+ function ge(i) {
8059
+ return i.pathname.replace(/^\/+/, "").split("/").map((e) => encodeURIComponent(w(e))).join("/");
8060
8060
  }
8061
- function pe(i, e) {
8061
+ function he(i, e) {
8062
8062
  return /^[a-z][a-z\d+.-]*:/i.test(i) || i.startsWith("//") ? i : /^[a-z][a-z\d+.-]*:/i.test(e) ? new URL(i, e.endsWith("/") ? e : `${e}/`).toString() : I(e, i);
8063
8063
  }
8064
- function S(i) {
8064
+ function D(i, e) {
8065
+ const o = e.replace(/[?#].*$/, "").replace(/\/+$/, "");
8066
+ return (i === _ || i.startsWith(`${_}/`)) && /(?:^|\/)api\/v1$/i.test(o) ? `${o}${i.slice(_.length)}` : /^[a-z][a-z\d+.-]*:/i.test(e) ? new URL(i, e).toString() : i;
8067
+ }
8068
+ function C(i) {
8065
8069
  const e = i.resourceBaseUrl;
8066
8070
  if (e)
8067
- return e.startsWith("/") && !e.startsWith("//") && /^[a-z][a-z\d+.-]*:/i.test(i.apiBaseUrl) ? new URL(e, i.apiBaseUrl).toString() : e;
8071
+ return e.startsWith("/") && !e.startsWith("//") ? D(e, i.apiBaseUrl) : e;
8068
8072
  }
8069
8073
  function p(i, e) {
8070
- const o = A(i);
8074
+ const o = S(i);
8071
8075
  if (o)
8072
8076
  return o;
8073
8077
  if (i.startsWith("/") && !i.startsWith("//"))
8074
- return /^[a-z][a-z\d+.-]*:/i.test(e.apiBaseUrl) ? new URL(i, e.apiBaseUrl).toString() : i;
8078
+ return D(i, e.apiBaseUrl);
8075
8079
  let t;
8076
8080
  try {
8077
8081
  t = new URL(i);
8078
8082
  } catch {
8079
- const d = S(e);
8080
- return d ? pe(i, d) : i;
8083
+ const d = C(e);
8084
+ return d ? he(i, d) : i;
8081
8085
  }
8082
8086
  const n = t.protocol.slice(0, -1).toLowerCase();
8083
- if (!T.has(n))
8087
+ if (!E.has(n))
8084
8088
  return i;
8085
8089
  const a = t.hostname || e.dictionaryId;
8086
8090
  if (n === "gico")
8087
8091
  return e.iconUrl ? p(e.iconUrl, {
8088
8092
  ...e,
8089
8093
  iconUrl: void 0
8090
- }) : A("qrc:///icons/document.png") ?? "";
8091
- const r = me(t), l = `${e.apiBaseUrl.replace(/\/+$/, "")}/dictionaries/${encodeURIComponent(a)}/resources`, m = I(S(e) ?? l, r);
8094
+ }) : S("qrc:///icons/document.png") ?? "";
8095
+ const r = ge(t), l = `${e.apiBaseUrl.replace(/\/+$/, "")}/dictionaries/${encodeURIComponent(a)}/resources`, m = I(C(e) ?? l, r);
8092
8096
  return t.hash ? `${m}${t.hash}` : m;
8093
8097
  }
8094
- function ge(i) {
8098
+ function fe(i) {
8095
8099
  const e = /^([a-z][a-z\d+.-]*):(.*)$/i.exec(i);
8096
8100
  if (!e)
8097
8101
  return;
@@ -8103,31 +8107,31 @@ function ge(i) {
8103
8107
  const r = new URL(i);
8104
8108
  t = r.searchParams.get("word") ?? r.pathname.replace(/^\/+/, ""), n = r.searchParams.get("gdanchor") ?? (r.hash.slice(1) || void 0), a = r.searchParams.get("dictionaries")?.split(",").filter(Boolean), !t && (o === "bword" || o === "entry") && (t = r.hostname);
8105
8109
  } catch {
8106
- const r = e[2]?.replace(/^\/{0,2}/, "") ?? "", [l, m] = r.split("#", 2), [d, w] = (l ?? "").split("?", 2);
8107
- t = d ?? "", n = new URLSearchParams(w ?? "").get("gdanchor") ?? (m || void 0);
8110
+ const r = e[2]?.replace(/^\/{0,2}/, "") ?? "", [l, m] = r.split("#", 2), [d, b] = (l ?? "").split("?", 2);
8111
+ t = d ?? "", n = new URLSearchParams(b ?? "").get("gdanchor") ?? (m || void 0);
8108
8112
  }
8109
- return t = f(t.replace(/^\/+/, "")), t ? {
8113
+ return t = w(t.replace(/^\/+/, "")), t ? {
8110
8114
  kind: "lookup",
8111
8115
  word: t,
8112
- ...n ? { anchor: f(n) } : {},
8116
+ ...n ? { anchor: w(n) } : {},
8113
8117
  ...a?.length ? { dictionaryIds: a } : {}
8114
8118
  } : { kind: "unsafe" };
8115
8119
  }
8116
- function D(i, e) {
8120
+ function L(i, e) {
8117
8121
  const o = i.trim();
8118
8122
  if (!o || o === "#")
8119
8123
  return { kind: "anchor", anchor: "" };
8120
8124
  if (o.startsWith("#"))
8121
- return { kind: "anchor", anchor: f(o.slice(1)) };
8122
- const t = ge(o);
8125
+ return { kind: "anchor", anchor: w(o.slice(1)) };
8126
+ const t = fe(o);
8123
8127
  if (t)
8124
8128
  return t;
8125
8129
  const n = /^([a-z][a-z\d+.-]*):/i.exec(o)?.[1]?.toLowerCase();
8126
8130
  if (n === "javascript" || n === "vbscript" || n === "file" || n === "data")
8127
8131
  return { kind: "unsafe" };
8128
- if (n && ce.has(n))
8132
+ if (n && pe.has(n))
8129
8133
  return { kind: "unsafe" };
8130
- if (n && T.has(n))
8134
+ if (n && E.has(n))
8131
8135
  return { kind: n === "gdau" ? "audio" : n === "gdvideo" ? "video" : "resource", url: p(o, e) };
8132
8136
  if (o.startsWith("//") || n === "http" || n === "https" || n === "mailto" || n === "tel")
8133
8137
  return { kind: "external", url: o };
@@ -8138,15 +8142,15 @@ function D(i, e) {
8138
8142
  const [a, r] = o.split("#", 2);
8139
8143
  return a ? {
8140
8144
  kind: "lookup",
8141
- word: f(a),
8142
- ...r ? { anchor: f(r) } : {}
8143
- } : { kind: "anchor", anchor: f(r ?? "") };
8145
+ word: w(a),
8146
+ ...r ? { anchor: w(r) } : {}
8147
+ } : { kind: "anchor", anchor: w(r ?? "") };
8144
8148
  }
8145
- const he = ["src", "poster", "data"];
8149
+ const we = ["src", "poster", "data"];
8146
8150
  function x(i) {
8147
8151
  return /^(?:data:|blob:|https?:|#)/i.test(i);
8148
8152
  }
8149
- function fe(i, e, o) {
8153
+ function be(i, e, o) {
8150
8154
  const t = [
8151
8155
  ["data-gd-audio", "audio"],
8152
8156
  ["data-gd-video", "video"],
@@ -8167,7 +8171,7 @@ function fe(i, e, o) {
8167
8171
  const a = i.getAttribute("data-gd-lookup")?.trim();
8168
8172
  if (a && a !== "true" && a !== "1")
8169
8173
  return { kind: "lookup", word: a };
8170
- const r = D(e, o);
8174
+ const r = L(e, o);
8171
8175
  if (r.kind === "lookup")
8172
8176
  return r;
8173
8177
  const l = i.getAttribute("data-gd-word")?.trim();
@@ -8176,7 +8180,7 @@ function fe(i, e, o) {
8176
8180
  if (n === "unsafe")
8177
8181
  return { kind: "unsafe" };
8178
8182
  }
8179
- function we(i, e, o) {
8183
+ function ke(i, e, o) {
8180
8184
  switch (e.kind) {
8181
8185
  case "anchor":
8182
8186
  i.setAttribute(
@@ -8203,7 +8207,7 @@ function we(i, e, o) {
8203
8207
  break;
8204
8208
  }
8205
8209
  }
8206
- function C(i, e) {
8210
+ function T(i, e) {
8207
8211
  return i.replace(
8208
8212
  /url\(\s*(["']?)([^"')]+)\1\s*\)/gi,
8209
8213
  (t, n, a) => {
@@ -8215,13 +8219,13 @@ function C(i, e) {
8215
8219
  (t, n, a) => x(a) ? t : `@import ${n}${p(a, e)}${n}`
8216
8220
  );
8217
8221
  }
8218
- function be(i, e) {
8222
+ function ue(i, e) {
8219
8223
  return i.split(/,\s+(?=[^,]+(?:\s+\d+(?:\.\d+)?[wx])?(?:,|$))/).map((o) => {
8220
8224
  const t = /^(\S+)([\s\S]*)$/.exec(o.trim());
8221
8225
  return !t?.[1] || x(t[1]) ? o.trim() : `${p(t[1], e)}${t[2] ?? ""}`;
8222
8226
  }).join(", ");
8223
8227
  }
8224
- function ke(i) {
8228
+ function xe(i) {
8225
8229
  if (!i.classList.contains("hidden_expand_opt"))
8226
8230
  return;
8227
8231
  const e = i.getAttribute("onclick") ?? "", o = /gdExpandOptPart\(\s*['"]([^'"]+)['"]\s*,\s*['"]([^'"]+)['"]\s*\)/.exec(
@@ -8229,7 +8233,7 @@ function ke(i) {
8229
8233
  );
8230
8234
  o?.[1] && o[2] && (i.setAttribute("data-gd-expander", o[1]), i.setAttribute("data-gd-optional", o[2]));
8231
8235
  }
8232
- function ue(i, e, o) {
8236
+ function ye(i, e, o) {
8233
8237
  if (typeof document > "u")
8234
8238
  throw new Error("Article rendering requires a browser document");
8235
8239
  const t = {
@@ -8242,37 +8246,37 @@ function ue(i, e, o) {
8242
8246
  r.remove();
8243
8247
  }), o === "none" && a.querySelectorAll("script").forEach((r) => r.remove());
8244
8248
  for (const r of a.querySelectorAll("*")) {
8245
- if (ke(r), o === "none")
8249
+ if (xe(r), o === "none")
8246
8250
  for (const d of [...r.attributes])
8247
8251
  (/^on/i.test(d.name) || d.name.toLowerCase() === "srcdoc") && r.removeAttribute(d.name);
8248
8252
  if (r instanceof HTMLAnchorElement || r.tagName === "AREA") {
8249
8253
  const d = r.getAttribute("href");
8250
- d !== null && we(
8254
+ d !== null && ke(
8251
8255
  r,
8252
- fe(r, d, t) ?? D(d, t),
8256
+ be(r, d, t) ?? L(d, t),
8253
8257
  i.dictionaryId
8254
8258
  );
8255
8259
  } else if (r.hasAttribute("href")) {
8256
8260
  const d = r.getAttribute("href") ?? "";
8257
8261
  x(d) || r.setAttribute("href", p(d, t));
8258
8262
  }
8259
- for (const d of he) {
8260
- const w = r.getAttribute(d);
8261
- w === null || x(w) || (/^(?:javascript|vbscript|file):/i.test(w) ? r.removeAttribute(d) : r.setAttribute(d, p(w, t)));
8263
+ for (const d of we) {
8264
+ const b = r.getAttribute(d);
8265
+ b === null || x(b) || (/^(?:javascript|vbscript|file):/i.test(b) ? r.removeAttribute(d) : r.setAttribute(d, p(b, t)));
8262
8266
  }
8263
8267
  const l = r.getAttribute("srcset");
8264
- l && r.setAttribute("srcset", be(l, t));
8268
+ l && r.setAttribute("srcset", ue(l, t));
8265
8269
  const m = r.getAttribute("style");
8266
8270
  m && r.setAttribute(
8267
8271
  "style",
8268
- C(m, t)
8272
+ T(m, t)
8269
8273
  );
8270
8274
  }
8271
8275
  for (const r of a.querySelectorAll("style"))
8272
- r.textContent = C(r.textContent ?? "", t);
8276
+ r.textContent = T(r.textContent ?? "", t);
8273
8277
  return a.innerHTML;
8274
8278
  }
8275
- const xe = {
8279
+ const ve = {
8276
8280
  fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, Arial, sans-serif',
8277
8281
  textColor: "#222222",
8278
8282
  mutedTextColor: "#555555",
@@ -8286,8 +8290,8 @@ const xe = {
8286
8290
  selectionTextColor: "#ffffff",
8287
8291
  radius: "8px",
8288
8292
  spacing: "8px"
8289
- }, ye = {
8290
- fontFamily: xe.fontFamily,
8293
+ }, _e = {
8294
+ fontFamily: ve.fontFamily,
8291
8295
  textColor: "#edf1f5",
8292
8296
  mutedTextColor: "#aeb8c3",
8293
8297
  linkColor: "#79bfff",
@@ -8301,7 +8305,7 @@ const xe = {
8301
8305
  radius: "8px",
8302
8306
  spacing: "8px"
8303
8307
  };
8304
- function E(i = "light") {
8308
+ function q(i = "light") {
8305
8309
  return i !== "auto" ? i : globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
8306
8310
  }
8307
8311
  function c(i, e) {
@@ -8310,8 +8314,8 @@ function c(i, e) {
8310
8314
  function k(i) {
8311
8315
  return i.replace(/<\/style/gi, "<\\/style");
8312
8316
  }
8313
- function ve(i = {}) {
8314
- const e = E(i.mode), o = i.tokens ?? {}, t = e === "dark" ? { ...ye, ...o } : o, n = [
8317
+ function ze(i = {}) {
8318
+ const e = q(i.mode), o = i.tokens ?? {}, t = e === "dark" ? { ..._e, ...o } : o, n = [
8315
8319
  c("--gd-font-family", t.fontFamily),
8316
8320
  c("--gd-text-color", t.textColor),
8317
8321
  c("--gd-muted-text-color", t.mutedTextColor),
@@ -8345,24 +8349,24 @@ function ve(i = {}) {
8345
8349
  function g(i) {
8346
8350
  return i.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
8347
8351
  }
8348
- function _e(i) {
8352
+ function Ae(i) {
8349
8353
  return i.replace(
8350
8354
  /[^a-zA-Z0-9_-]/g,
8351
8355
  (e) => `_u${e.codePointAt(0)?.toString(16) ?? "0"}_`
8352
8356
  );
8353
8357
  }
8354
- function ze(i) {
8358
+ function Se(i) {
8355
8359
  return (i ?? "unknown").toLowerCase().replace(/[^a-z0-9_-]/g, "-");
8356
8360
  }
8357
- function Ae(i, e) {
8361
+ function Ce(i, e) {
8358
8362
  return i.iconUrl ? p(i.iconUrl, {
8359
8363
  apiBaseUrl: e,
8360
8364
  dictionaryId: i.dictionaryId,
8361
8365
  ...i.resourceBaseUrl ? { resourceBaseUrl: i.resourceBaseUrl } : {}
8362
8366
  }) : u["document.png"];
8363
8367
  }
8364
- function Se(i, e, o) {
8365
- const t = g(i.dictionaryId), n = _e(i.dictionaryId), a = ue(i, e, o), r = ze(i.sourceLanguage), l = g(i.targetLanguage ?? ""), m = g(Ae(i, e));
8368
+ function Te(i, e, o) {
8369
+ const t = g(i.dictionaryId), n = Ae(i.dictionaryId), a = ye(i, e, o), r = Se(i.sourceLanguage), l = g(i.targetLanguage ?? ""), m = g(Ce(i, e));
8366
8370
  return `
8367
8371
  <article class="gdarticle" id="gdfrom-${n}" data-gd-id="${t}">
8368
8372
  <gd-dict-header class="gddictname" id="gddictname-${n}"
@@ -8380,7 +8384,7 @@ function Se(i, e, o) {
8380
8384
  <div style="clear:both;" aria-hidden="true"></div>
8381
8385
  <span class="gdarticleseparator"></span>`;
8382
8386
  }
8383
- function Ce(i) {
8387
+ function Ee(i) {
8384
8388
  return i.length ? `<div class="gdstemmedsuggestion">
8385
8389
  <span class="gdstemmedsuggestion_head">Close words: </span>
8386
8390
  <span class="gdstemmedsuggestion_body">${i.map(
@@ -8388,7 +8392,7 @@ function Ce(i) {
8388
8392
  ).join(", ")}</span>
8389
8393
  </div>` : "";
8390
8394
  }
8391
- function Te(i, e) {
8395
+ function Ie(i, e) {
8392
8396
  return `(function(){
8393
8397
  "use strict";
8394
8398
  const config=${JSON.stringify({
@@ -8404,6 +8408,32 @@ function Te(i, e) {
8404
8408
  type,
8405
8409
  detail
8406
8410
  },"*");
8411
+ const reportResourceError=(failure)=>{
8412
+ if(!failure||typeof failure.url!=="string"||!failure.url)return;
8413
+ if(failure.resourceType!=="stylesheet"&&failure.resourceType!=="script")return;
8414
+ post("resource-error",{
8415
+ resourceType:failure.resourceType,
8416
+ url:failure.url,
8417
+ dictionaryId:typeof failure.dictionaryId==="string"&&failure.dictionaryId
8418
+ ?failure.dictionaryId
8419
+ :undefined
8420
+ });
8421
+ };
8422
+ globalThis.__GOLDENDICT_WEB_REPORT_RESOURCE_ERROR__=reportResourceError;
8423
+ const pendingResourceErrors=globalThis.__GOLDENDICT_WEB_RESOURCE_ERRORS__;
8424
+ if(Array.isArray(pendingResourceErrors)){
8425
+ pendingResourceErrors.splice(0).forEach(reportResourceError);
8426
+ }
8427
+ const verifyStylesheets=()=>{
8428
+ document.querySelectorAll('link[rel~="stylesheet"][href]').forEach((link)=>{
8429
+ if(!(link instanceof HTMLLinkElement)||link.disabled||link.sheet!==null)return;
8430
+ reportResourceError({
8431
+ resourceType:"stylesheet",
8432
+ url:link.href,
8433
+ dictionaryId:link.closest(".gdarticle")?.getAttribute("data-gd-id")||undefined
8434
+ });
8435
+ });
8436
+ };
8407
8437
  const articleOf=(target)=>target instanceof Element?target.closest(".gdarticle"):null;
8408
8438
  const articleId=(article)=>article?.getAttribute("data-gd-id")||"";
8409
8439
  const syncDictionaryTheme=()=>{
@@ -8545,10 +8575,10 @@ function Te(i, e) {
8545
8575
  const resizeObserver=new ResizeObserver(requestSize);
8546
8576
  resizeObserver.observe(document.body);
8547
8577
  addEventListener("resize",requestSize,{passive:true});
8548
- addEventListener("load",()=>{requestSize();post("ready",{});});
8578
+ addEventListener("load",()=>{verifyStylesheets();requestSize();post("ready",{});});
8549
8579
  })();`;
8550
8580
  }
8551
- function Ie(i, e) {
8581
+ function De(i, e) {
8552
8582
  const o = i === "none" ? `'nonce-${e}'` : "'unsafe-inline' 'unsafe-eval' data: blob: http: https:", t = i === "none" ? "'none'" : "http: https:";
8553
8583
  return [
8554
8584
  "default-src 'none'",
@@ -8564,39 +8594,66 @@ function Ie(i, e) {
8564
8594
  "base-uri 'none'"
8565
8595
  ].join("; ");
8566
8596
  }
8567
- function De() {
8568
- return 'globalThis.__DICT__={name:"GoldenDict",version:"web"};';
8597
+ function Le() {
8598
+ return `(function(){
8599
+ globalThis.__DICT__={name:"GoldenDict",version:"web"};
8600
+ const pending=[];
8601
+ globalThis.__GOLDENDICT_WEB_RESOURCE_ERRORS__=pending;
8602
+ addEventListener("error",(event)=>{
8603
+ const target=event.target;
8604
+ let resourceType="";
8605
+ let url="";
8606
+ if(target instanceof HTMLLinkElement&&target.relList.contains("stylesheet")){
8607
+ resourceType="stylesheet";
8608
+ url=target.href;
8609
+ }else if(target instanceof HTMLScriptElement&&target.src){
8610
+ resourceType="script";
8611
+ url=target.src;
8612
+ }
8613
+ if(!resourceType||!url)return;
8614
+ const article=target.closest(".gdarticle");
8615
+ const failure={
8616
+ resourceType,
8617
+ url,
8618
+ dictionaryId:article?.getAttribute("data-gd-id")||undefined
8619
+ };
8620
+ const report=globalThis.__GOLDENDICT_WEB_REPORT_RESOURCE_ERROR__;
8621
+ if(typeof report==="function")report(failure);
8622
+ else pending.push(failure);
8623
+ },true);
8624
+ })();`;
8569
8625
  }
8570
- function Ee(i, e) {
8571
- const o = e.theme ?? {}, t = E(o.mode), n = e.layoutMode ?? "responsive", a = e.instanceId.replace(/[^a-zA-Z0-9_-]/g, ""), r = i.articles.map(
8572
- (d) => Se(d, e.apiBaseUrl, e.scriptPolicy)
8626
+ function qe(i, e) {
8627
+ const o = e.theme ?? {}, t = q(o.mode), n = e.layoutMode ?? "responsive", a = e.instanceId.replace(/[^a-zA-Z0-9_-]/g, ""), r = i.articles.map(
8628
+ (d) => Te(d, e.apiBaseUrl, e.scriptPolicy)
8573
8629
  ).join(""), l = r ? `${r}<div class="empty-space" aria-hidden="true"></div>` : `<div class="gdnotfound"><p>No translation for <b>${g(i.word)}</b> was found.</p></div>`, m = o.brandName ? `${i.word} — ${o.brandName}` : i.word;
8574
8630
  return `<!doctype html>
8575
8631
  <html data-gd-theme="${t}" data-gd-layout="${n}" data-darkreader-scheme="${t}"><head>
8576
8632
  <meta charset="utf-8">
8577
8633
  <meta name="viewport" content="width=device-width,initial-scale=1">
8578
- <meta http-equiv="Content-Security-Policy" content="${g(Ie(e.scriptPolicy, a))}">
8634
+ <meta http-equiv="Content-Security-Policy" content="${g(De(e.scriptPolicy, a))}">
8579
8635
  <title>${g(m)}</title>
8580
- <script nonce="${a}" data-gd-runtime="compatibility">${De()}<\/script>
8581
- <style>${k(re)}</style>
8582
- <style>${k(de(o.preset))}</style>
8583
- ${n === "responsive" ? `<style data-gd-style="responsive">${k(le)}</style>` : ""}
8584
- <style>${ve(o)}</style>
8585
- <style media="print">${k(ae)}</style>
8636
+ <script nonce="${a}" data-gd-runtime="compatibility">${Le()}<\/script>
8637
+ <style>${k(de)}</style>
8638
+ <style>${k(se(o.preset))}</style>
8639
+ ${n === "responsive" ? `<style data-gd-style="responsive">${k(ce)}</style>` : ""}
8640
+ <style>${ze(o)}</style>
8641
+ <style media="print">${k(le)}</style>
8586
8642
  </head><body>
8587
8643
  ${l}
8588
- ${Ce(i.suggestions)}
8589
- <script nonce="${a}">${Te(e.instanceId, t).replace(/<\/script/gi, "<\\/script")}<\/script>
8644
+ ${Ee(i.suggestions)}
8645
+ <script nonce="${a}">${Ie(e.instanceId, t).replace(/<\/script/gi, "<\\/script")}<\/script>
8590
8646
  </body></html>`;
8591
8647
  }
8592
- const b = {
8648
+ const f = {
8593
8649
  lookup: "goldendict-lookup",
8594
8650
  activeArticleChange: "goldendict-active-article-change",
8595
8651
  articleToggle: "goldendict-article-toggle",
8596
8652
  mediaRequest: "goldendict-media-request",
8597
8653
  externalLink: "goldendict-external-link",
8654
+ resourceError: "goldendict-resource-error",
8598
8655
  stateChange: "goldendict-state-change"
8599
- }, qe = `
8656
+ }, Me = `
8600
8657
  :host{display:block;box-sizing:border-box;width:100%;min-width:0;max-width:100%;color:#222;font-family:system-ui,sans-serif;container:goldendict-view / inline-size}
8601
8658
  .shell{position:relative;box-sizing:border-box;width:100%;min-width:0;max-width:100%;min-height:8rem;border-radius:var(--gd-host-radius,8px);overflow:hidden;background:var(--gd-host-background,#fff)}
8602
8659
  .brand{display:flex;align-items:center;gap:.65rem;min-width:0;padding:.65rem .9rem;border-bottom:1px solid var(--gd-host-border,#e3e3e3);background:var(--gd-host-surface,#f7f9fb);font-weight:650}
@@ -8604,7 +8661,7 @@ const b = {
8604
8661
  .brand img{display:block;flex:0 0 auto;width:1.75rem;height:1.75rem;object-fit:contain}
8605
8662
  .brand img[hidden]{display:none}
8606
8663
  .brand span{min-width:0;overflow-wrap:anywhere}
8607
- .status{display:grid;place-items:center;min-height:8rem;padding:1.25rem;text-align:center;color:var(--gd-host-muted,#59636e)}
8664
+ .status{display:grid;place-items:center;min-height:8rem;padding:1.25rem;overflow-wrap:anywhere;text-align:center;color:var(--gd-host-muted,#59636e)}
8608
8665
  .status[hidden]{display:none}
8609
8666
  .status[data-state="error"]{color:var(--gd-host-error,#a21d2d)}
8610
8667
  .spinner{width:1.25rem;height:1.25rem;border:2px solid currentColor;border-right-color:transparent;border-radius:50%;animation:spin .75s linear infinite;margin:0 auto .7rem}
@@ -8614,13 +8671,13 @@ const b = {
8614
8671
  @container goldendict-view (max-width:30rem){.brand{gap:.5rem;padding:.55rem .65rem}.status{padding:1rem .75rem}}
8615
8672
  @media (prefers-reduced-motion:reduce){.spinner{animation:none}}
8616
8673
  `;
8617
- function Le() {
8674
+ function Be() {
8618
8675
  return globalThis.crypto?.randomUUID?.() ?? `gd-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
8619
8676
  }
8620
- function Be(i) {
8677
+ function $e(i) {
8621
8678
  return (i instanceof DOMException || i instanceof Error) && i.name === "AbortError";
8622
8679
  }
8623
- class _ extends HTMLElement {
8680
+ class z extends HTMLElement {
8624
8681
  static observedAttributes = [
8625
8682
  "api-base",
8626
8683
  "word",
@@ -8629,7 +8686,7 @@ class _ extends HTMLElement {
8629
8686
  "script-policy",
8630
8687
  "layout-mode"
8631
8688
  ];
8632
- instanceId = Le();
8689
+ instanceId = Be();
8633
8690
  frame;
8634
8691
  statusElement;
8635
8692
  brandElement;
@@ -8643,12 +8700,14 @@ class _ extends HTMLElement {
8643
8700
  responseValue;
8644
8701
  themeValue = {};
8645
8702
  stateValue = "idle";
8703
+ errorValue;
8704
+ resourceErrorsValue = [];
8646
8705
  dictionaryIdsValue = [];
8647
8706
  pendingAnchor;
8648
8707
  constructor() {
8649
8708
  super();
8650
8709
  const e = this.attachShadow({ mode: "open" });
8651
- e.innerHTML = `<style>${qe}</style>
8710
+ e.innerHTML = `<style>${Me}</style>
8652
8711
  <section class="shell" part="container">
8653
8712
  <div class="brand" part="brand" hidden>
8654
8713
  <img alt="" hidden><span></span>
@@ -8717,6 +8776,14 @@ class _ extends HTMLElement {
8717
8776
  get response() {
8718
8777
  return this.responseValue;
8719
8778
  }
8779
+ /** The current request or article-resource error, if `state` is `"error"`. */
8780
+ get error() {
8781
+ return this.errorValue;
8782
+ }
8783
+ /** Dictionary-authored stylesheets or scripts that failed in this render. */
8784
+ get resourceErrors() {
8785
+ return this.resourceErrorsValue.map((e) => ({ ...e }));
8786
+ }
8720
8787
  configureClient(e) {
8721
8788
  this.clientValue = new v(e);
8722
8789
  }
@@ -8738,7 +8805,7 @@ class _ extends HTMLElement {
8738
8805
  return;
8739
8806
  this.setLookupResponse(r);
8740
8807
  } catch (r) {
8741
- if (n !== this.requestSequence || Be(r))
8808
+ if (n !== this.requestSequence || $e(r))
8742
8809
  return;
8743
8810
  const l = r instanceof Error ? r : new Error(String(r));
8744
8811
  this.responseValue = void 0, this.resetFrame(), this.setState("error", { word: t, error: l });
@@ -8759,11 +8826,13 @@ class _ extends HTMLElement {
8759
8826
  this.postCommand({ type: "scroll-article", dictionaryId: e });
8760
8827
  }
8761
8828
  renderResponse(e) {
8762
- const o = ++this.renderSequence, t = `${this.instanceId}-${o}`;
8829
+ const o = ++this.renderSequence;
8830
+ this.resourceErrorsValue = [], this.errorValue = void 0;
8831
+ const t = `${this.instanceId}-${o}`;
8763
8832
  this.activeBridgeInstanceId = t;
8764
8833
  const n = this.replaceFrame(!1);
8765
8834
  n.title = e.word ? `Dictionary results for ${e.word}` : "Dictionary article";
8766
- const a = Ee(e, {
8835
+ const a = qe(e, {
8767
8836
  apiBaseUrl: this.clientValue.baseUrl,
8768
8837
  instanceId: t,
8769
8838
  scriptPolicy: this.scriptPolicy,
@@ -8775,7 +8844,7 @@ class _ extends HTMLElement {
8775
8844
  });
8776
8845
  }
8777
8846
  resetFrame() {
8778
- this.activeBridgeInstanceId = void 0, this.replaceFrame(!0);
8847
+ this.activeBridgeInstanceId = void 0, this.resourceErrorsValue = [], this.replaceFrame(!0);
8779
8848
  }
8780
8849
  replaceFrame(e) {
8781
8850
  const o = this.frame, t = this.ownerDocument.createElement("iframe");
@@ -8784,7 +8853,10 @@ class _ extends HTMLElement {
8784
8853
  }), o.replaceWith(t), this.frame = t, t.offsetWidth, t;
8785
8854
  }
8786
8855
  handleFrameLoaded() {
8787
- this.responseValue && (this.setState(
8856
+ this.responseValue && (this.resourceErrorsValue.length ? this.setState("error", {
8857
+ word: this.responseValue.word,
8858
+ error: this.errorValue ?? this.resourceError(this.resourceErrorsValue[0])
8859
+ }) : this.setState(
8788
8860
  this.responseValue.articles.length ? "ready" : "not-found",
8789
8861
  { word: this.responseValue.word }
8790
8862
  ), this.pendingAnchor && (this.postCommand({ type: "scroll-anchor", anchor: this.pendingAnchor }), this.pendingAnchor = void 0));
@@ -8809,12 +8881,12 @@ class _ extends HTMLElement {
8809
8881
  this.handleLookupMessage(t);
8810
8882
  break;
8811
8883
  case "active-article":
8812
- this.emit(b.activeArticleChange, {
8884
+ this.emit(f.activeArticleChange, {
8813
8885
  dictionaryId: String(t.dictionaryId ?? "")
8814
8886
  });
8815
8887
  break;
8816
8888
  case "article-toggle":
8817
- this.emit(b.articleToggle, {
8889
+ this.emit(f.articleToggle, {
8818
8890
  dictionaryId: String(t.dictionaryId ?? ""),
8819
8891
  collapsed: !!t.collapsed
8820
8892
  });
@@ -8825,8 +8897,34 @@ class _ extends HTMLElement {
8825
8897
  case "external-link":
8826
8898
  this.handleExternalLink(String(t.url ?? ""));
8827
8899
  break;
8900
+ case "resource-error":
8901
+ this.handleResourceErrorMessage(t);
8902
+ break;
8828
8903
  }
8829
8904
  };
8905
+ handleResourceErrorMessage(e) {
8906
+ const o = e.resourceType === "stylesheet" || e.resourceType === "script" ? e.resourceType : void 0, t = String(e.url ?? "").trim();
8907
+ if (!o || !t)
8908
+ return;
8909
+ const n = {
8910
+ resourceType: o,
8911
+ url: t,
8912
+ ...e.dictionaryId ? { dictionaryId: String(e.dictionaryId) } : {}
8913
+ };
8914
+ this.resourceErrorsValue.some(
8915
+ (a) => a.resourceType === n.resourceType && a.url === n.url && a.dictionaryId === n.dictionaryId
8916
+ ) || (this.resourceErrorsValue.push(n), this.emit(
8917
+ f.resourceError,
8918
+ { ...n }
8919
+ ), this.setState("error", {
8920
+ word: this.responseValue?.word,
8921
+ error: this.resourceError(n)
8922
+ }));
8923
+ }
8924
+ resourceError(e) {
8925
+ const o = e.resourceType === "stylesheet" ? "stylesheet" : "script";
8926
+ return new Error(`Dictionary ${o} failed to load: ${e.url}`);
8927
+ }
8830
8928
  handleLookupMessage(e) {
8831
8929
  const o = String(e.word ?? "").trim();
8832
8930
  if (!o)
@@ -8836,7 +8934,7 @@ class _ extends HTMLElement {
8836
8934
  ...e.anchor ? { anchor: String(e.anchor) } : {},
8837
8935
  ...t.length ? { dictionaryIds: [...t] } : {}
8838
8936
  };
8839
- this.emit(b.lookup, n, !0).defaultPrevented || (this.pendingAnchor = n.anchor, this.lookup(o, t));
8937
+ this.emit(f.lookup, n, !0).defaultPrevented || (this.pendingAnchor = n.anchor, this.lookup(o, t));
8840
8938
  }
8841
8939
  handleMediaMessage(e) {
8842
8940
  const o = e.kind === "video" || e.kind === "resource" ? e.kind : "audio", t = {
@@ -8844,14 +8942,14 @@ class _ extends HTMLElement {
8844
8942
  url: String(e.url ?? ""),
8845
8943
  ...e.dictionaryId ? { dictionaryId: String(e.dictionaryId) } : {}
8846
8944
  };
8847
- !t.url || this.emit(b.mediaRequest, t, !0).defaultPrevented || (o === "audio" ? new Audio(t.url).play().catch(() => {
8945
+ !t.url || this.emit(f.mediaRequest, t, !0).defaultPrevented || (o === "audio" ? new Audio(t.url).play().catch(() => {
8848
8946
  }) : this.openExternal(t.url));
8849
8947
  }
8850
8948
  handleExternalLink(e) {
8851
8949
  if (!e)
8852
8950
  return;
8853
8951
  this.emit(
8854
- b.externalLink,
8952
+ f.externalLink,
8855
8953
  { url: e },
8856
8954
  !0
8857
8955
  ).defaultPrevented || this.openExternal(e);
@@ -8866,15 +8964,15 @@ class _ extends HTMLElement {
8866
8964
  }
8867
8965
  setState(e, o = {}) {
8868
8966
  const t = e !== this.stateValue;
8869
- if (this.stateValue = e, this.statusElement.dataset.state = e, this.statusElement.hidden = e === "ready" || e === "not-found", e === "loading") {
8967
+ if (this.stateValue = e, this.errorValue = e === "error" ? o.error ?? new Error("The dictionary request failed.") : void 0, this.statusElement.dataset.state = e, this.statusElement.hidden = e === "ready" || e === "not-found", e === "loading") {
8870
8968
  this.frame.hidden = !0, this.statusElement.innerHTML = '<div><div class="spinner" aria-hidden="true"></div>Looking up <strong></strong>…</div>';
8871
8969
  const n = this.statusElement.querySelector("strong");
8872
8970
  n && (n.textContent = o.word ?? "");
8873
- } else e === "error" ? this.statusElement.textContent = o.error?.message ?? "The dictionary request failed." : e === "idle" ? this.statusElement.textContent = "Enter a word to search the loaded dictionaries." : this.statusElement.textContent = e === "not-found" ? `No translation found for ${o.word ?? ""}.` : "";
8874
- t && this.emit(b.stateChange, {
8971
+ } else e === "error" ? this.statusElement.textContent = this.errorValue?.message ?? "The dictionary request failed." : e === "idle" ? this.statusElement.textContent = "Enter a word to search the loaded dictionaries." : this.statusElement.textContent = e === "not-found" ? `No translation found for ${o.word ?? ""}.` : "";
8972
+ t && this.emit(f.stateChange, {
8875
8973
  state: e,
8876
8974
  ...o.word ? { word: o.word } : {},
8877
- ...o.error ? { error: o.error } : {}
8975
+ ...this.errorValue ? { error: this.errorValue } : {}
8878
8976
  });
8879
8977
  }
8880
8978
  postCommand(e) {
@@ -8897,26 +8995,26 @@ class _ extends HTMLElement {
8897
8995
  return this.dispatchEvent(n), n;
8898
8996
  }
8899
8997
  }
8900
- function Me(i = "goldendict-view") {
8998
+ function Ue(i = "goldendict-view") {
8901
8999
  if (!globalThis.customElements)
8902
- return _;
9000
+ return z;
8903
9001
  const e = globalThis.customElements.get(i);
8904
- return e || (globalThis.customElements.define(i, _), _);
9002
+ return e || (globalThis.customElements.define(i, z), z);
8905
9003
  }
8906
- Me();
9004
+ Ue();
8907
9005
  export {
8908
- ye as DARK_THEME_TOKENS,
8909
- q as DictionaryApiError,
9006
+ _e as DARK_THEME_TOKENS,
9007
+ M as DictionaryApiError,
8910
9008
  v as DictionaryClient,
8911
- b as GOLDENDICT_EVENTS,
8912
- se as GOLDENDICT_SCHEME_SUPPORT,
8913
- _ as GoldenDictView,
8914
- xe as LIGHT_THEME_TOKENS,
8915
- D as classifyArticleLink,
8916
- Me as defineGoldendictView,
9009
+ f as GOLDENDICT_EVENTS,
9010
+ me as GOLDENDICT_SCHEME_SUPPORT,
9011
+ z as GoldenDictView,
9012
+ ve as LIGHT_THEME_TOKENS,
9013
+ L as classifyArticleLink,
9014
+ Ue as defineGoldendictView,
8917
9015
  k as escapeStyleText,
8918
9016
  p as resolveResourceUrl,
8919
- E as resolveThemeMode,
8920
- ve as themeToCss
9017
+ q as resolveThemeMode,
9018
+ ze as themeToCss
8921
9019
  };
8922
9020
  //# sourceMappingURL=index.js.map