@panda-lingo/goldendict 0.1.0 → 0.1.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/index.js CHANGED
@@ -1,11 +1,11 @@
1
- class E extends Error {
1
+ class q 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 q(i) {
8
+ function L(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 L(i) {
28
+ async function B(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 = q(e.baseUrl ?? "/api/v1");
43
+ this.baseUrl = L(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 L(t);
97
+ }), n = await B(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 E(
102
+ ))), new q(
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 B = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
111
+ const M = `<?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 B = `<?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", M = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
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"?>
158
158
  <!-- Created with Inkscape (http://www.inkscape.org/) -->
159
159
 
160
160
  <svg
@@ -196,7 +196,7 @@ const B = `<?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
- `, $ = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
199
+ `, F = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
200
200
  <!-- Created with Inkscape (http://www.inkscape.org/) -->
201
201
 
202
202
  <svg
@@ -311,7 +311,7 @@ const B = `<?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
- `, F = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAATrAAAE6wHYKlsNAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAcRJREFUOI2lkztvE0EQgL8Z7/rB2T5fCixhQQc00FAjJCRkiTYV/JH0adIgfgJVGn4CKRBUSIjCHYiOBimK7KA4ORw/dofC3Ck2dhpGGu1r5pvZmV0xM/5HXDEZDAbf2u12BkiM0UIImBlmRoyxHBeLBaPRaNzv9++tAJIkyVS1673HzBCRUtfFzEo/d/VAVRERzvf2uDw6AqB6eMhlt1va9Hq9FWgJiDEiIqgqcTwmnp4CUPeearu9EmRjDYp7qiqVNEV3dgCYx8hlniMimBlZlm0GFN0QERoHB7j9/bIGVUDiHCrVfzLQqwDvPSLCZDIhz3MuLi6YTye4eY58fkOnUbkeUERMkoRWq0WaptRqDaYfXvPr3StmP75cX4PZbIb3HoDx6TmttImveZoPn9N+0KfWvbsdYGY45xARvn76zvu3H8m6GS/2dpnefLRsb4Bb2wAhBJxbLoc/hwCcDc9QqVCvuzLy+uPa2IUnu4+p36hz5/5tGkmdxWKBc45Op0MIYXsNClAzTXj28imquqKFzUbA8fHxbzMbi0glhKBmpsuEREQkqmpU1Sgi8eTkJC/8ZNN3FhEHNIHG360pkJvZdN32D0SOwDehr1HXAAAAAElFTkSuQmCC", R = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
314
+ `, R = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAATrAAAE6wHYKlsNAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAcRJREFUOI2lkztvE0EQgL8Z7/rB2T5fCixhQQc00FAjJCRkiTYV/JH0adIgfgJVGn4CKRBUSIjCHYiOBimK7KA4ORw/dofC3Ck2dhpGGu1r5pvZmV0xM/5HXDEZDAbf2u12BkiM0UIImBlmRoyxHBeLBaPRaNzv9++tAJIkyVS1673HzBCRUtfFzEo/d/VAVRERzvf2uDw6AqB6eMhlt1va9Hq9FWgJiDEiIqgqcTwmnp4CUPeearu9EmRjDYp7qiqVNEV3dgCYx8hlniMimBlZlm0GFN0QERoHB7j9/bIGVUDiHCrVfzLQqwDvPSLCZDIhz3MuLi6YTye4eY58fkOnUbkeUERMkoRWq0WaptRqDaYfXvPr3StmP75cX4PZbIb3HoDx6TmttImveZoPn9N+0KfWvbsdYGY45xARvn76zvu3H8m6GS/2dpnefLRsb4Bb2wAhBJxbLoc/hwCcDc9QqVCvuzLy+uPa2IUnu4+p36hz5/5tGkmdxWKBc45Op0MIYXsNClAzTXj28imquqKFzUbA8fHxbzMbi0glhKBmpsuEREQkqmpU1Sgi8eTkJC/8ZNN3FhEHNIHG360pkJvZdN32D0SOwDehr1HXAAAAAElFTkSuQmCC", N = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
315
315
  <!-- Created with Inkscape (http://www.inkscape.org/) -->
316
316
 
317
317
  <svg
@@ -399,7 +399,7 @@ const B = `<?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
- `, N = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
402
+ `, O = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
403
403
  <!-- Created with Inkscape (http://www.inkscape.org/) -->
404
404
 
405
405
  <svg
@@ -515,7 +515,7 @@ const B = `<?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
- `, O = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
518
+ `, H = `<?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 B = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
575
575
  id="path2"
576
576
  style="fill:url(#radialGradient2)" />
577
577
  </svg>
578
- `, H = `<?xml version="1.0" encoding="UTF-8"?>
578
+ `, W = `<?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>
@@ -699,7 +699,7 @@ const B = `<?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
- `, W = `<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
+ `, 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">
703
703
  <defs>
704
704
  <linearGradient id="videoGrad" y2="100%">
705
705
  <stop stop-color="#FF5F6D" offset="0"/>
@@ -709,7 +709,7 @@ const B = `<?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
- `, 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">
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">
713
713
  <defs>
714
714
  <linearGradient id="warnGrad" y2="100%">
715
715
  <stop stop-color="#FF5F6D" offset="0"/>
@@ -724,31 +724,31 @@ const B = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
724
724
  function s(i) {
725
725
  return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(i)}`;
726
726
  }
727
- const k = {
728
- "arrow.svg": s(B),
727
+ const u = {
728
+ "arrow.svg": s(M),
729
729
  "audio.png": U,
730
- "collapse_article.svg": s($),
731
- "collapse_article_hovered.svg": s(M),
730
+ "collapse_article.svg": s(F),
731
+ "collapse_article_hovered.svg": s($),
732
732
  "collapse_opt.svg": s(P),
733
- "document.png": F,
734
- "downarrow.svg": s(R),
735
- "expand_article.svg": s(N),
733
+ "document.png": R,
734
+ "downarrow.svg": s(N),
735
+ "expand_article.svg": s(O),
736
736
  "expand_article_hovered.svg": s(G),
737
737
  "expand_opt.svg": s(V),
738
- "old-arrow.svg": s(O),
739
- "old-downarrow.svg": s(H),
738
+ "old-arrow.svg": s(H),
739
+ "old-downarrow.svg": s(W),
740
740
  "playsound.svg": s(j),
741
- "video.svg": s(W),
742
- "warning.svg": s(Z)
741
+ "video.svg": s(Z),
742
+ "warning.svg": s(Q)
743
743
  };
744
744
  function A(i) {
745
745
  const e = /^qrc:\/{2,3}(?:icons\/)?([^?#]+)(?:[?#].*)?$/i.exec(i);
746
- return e?.[1] ? k[e[1]] : void 0;
746
+ return e?.[1] ? u[e[1]] : void 0;
747
747
  }
748
748
  function z(i) {
749
749
  return i.replace(
750
750
  /qrc:\/{2,3}icons\/([a-z0-9_.-]+)/gi,
751
- (e, o) => k[o] ?? e
751
+ (e, o) => u[o] ?? e
752
752
  );
753
753
  }
754
754
  const h = { "article-style.css": `/******** Global, non-dictionary-specific classes ***********/
@@ -7883,25 +7883,151 @@ a:hover {
7883
7883
  code::selection {
7884
7884
  background: #333333;
7885
7885
  }
7886
- ` }, Q = h["article-style.css"], X = h["article-style-print.css"], J = h["article-style-st-babylon.css"], K = h["article-style-st-classic.css"], Y = h["article-style-st-lingoes-blue.css"], ee = h["article-style-st-lingoes.css"], ie = h["article-style-st-lingvo.css"], te = h["article-style-st-modern.css"], oe = {
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 = {
7887
7887
  default: "",
7888
- classic: K,
7889
- modern: te,
7890
- lingvo: ie,
7888
+ classic: Y,
7889
+ modern: oe,
7890
+ lingvo: te,
7891
7891
  babylon: J,
7892
- lingoes: ee,
7893
- "lingoes-blue": Y
7894
- }, ne = z(Q), re = z(X);
7895
- function ae(i = "default") {
7896
- return z(oe[i]);
7897
- }
7898
- const T = /* @__PURE__ */ new Set([
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 = `
7899
+ :root {
7900
+ --gd-responsive-gutter: clamp(0.5rem, 2.5vw, 1rem);
7901
+ }
7902
+
7903
+ html,
7904
+ body {
7905
+ box-sizing: border-box;
7906
+ inline-size: 100%;
7907
+ min-inline-size: 0;
7908
+ max-inline-size: 100%;
7909
+ }
7910
+
7911
+ *,
7912
+ *::before,
7913
+ *::after {
7914
+ box-sizing: inherit;
7915
+ }
7916
+
7917
+ body {
7918
+ margin: 0;
7919
+ padding: var(--gd-responsive-gutter);
7920
+ overflow-wrap: break-word;
7921
+ }
7922
+
7923
+ .gdarticle,
7924
+ .gdarticlebody,
7925
+ .gdstemmedsuggestion {
7926
+ min-inline-size: 0;
7927
+ max-inline-size: 100%;
7928
+ }
7929
+
7930
+ .gddictname {
7931
+ display: flex;
7932
+ align-items: center;
7933
+ gap: 0.4rem;
7934
+ max-inline-size: 100%;
7935
+ }
7936
+
7937
+ .gddicticon,
7938
+ .collapse_expand_area {
7939
+ flex: 0 0 auto;
7940
+ }
7941
+
7942
+ .gddicttitle {
7943
+ flex: 1 1 auto;
7944
+ min-inline-size: 0;
7945
+ overflow-wrap: anywhere;
7946
+ }
7947
+
7948
+ .collapse_expand_area {
7949
+ margin-inline-start: auto;
7950
+ }
7951
+
7952
+ .gddictname:focus-visible {
7953
+ outline: 2px solid var(--link-color, currentColor);
7954
+ outline-offset: -2px;
7955
+ }
7956
+
7957
+ /* Keep nested, absolutely positioned sidecar controls at their authored size. */
7958
+ .gdarticlebody > :where(div, section, article, aside, header, footer, figure),
7959
+ .gdarticlebody :where(img, picture, video, canvas, svg, iframe, object, embed),
7960
+ .gdarticlebody :where(pre, table) {
7961
+ max-inline-size: 100% !important;
7962
+ }
7963
+
7964
+ .gdarticlebody :where(img, video, canvas, svg) {
7965
+ block-size: auto !important;
7966
+ }
7967
+
7968
+ .gdarticlebody :where(a, p, li, dd, dt, td, th, code) {
7969
+ overflow-wrap: anywhere;
7970
+ }
7971
+
7972
+ .gdarticlebody pre {
7973
+ overflow-x: auto !important;
7974
+ overscroll-behavior-inline: contain;
7975
+ -webkit-overflow-scrolling: touch;
7976
+ }
7977
+
7978
+ .gdstemmedsuggestion_body {
7979
+ inline-size: auto;
7980
+ margin-inline: 0.75rem;
7981
+ }
7982
+
7983
+ .empty-space {
7984
+ block-size: clamp(6rem, 20vw, 15rem);
7985
+ }
7986
+
7987
+ @media (max-width: 64rem) {
7988
+ .gdarticlebody table {
7989
+ display: block !important;
7990
+ overflow-x: auto !important;
7991
+ overscroll-behavior-inline: contain;
7992
+ -webkit-overflow-scrolling: touch;
7993
+ }
7994
+ }
7995
+
7996
+ @media (max-width: 40rem) {
7997
+ :root {
7998
+ --gd-responsive-gutter: 0.5rem;
7999
+ }
8000
+
8001
+ .gddictname {
8002
+ min-block-size: 2.75rem;
8003
+ margin-block: 0.35rem;
8004
+ }
8005
+
8006
+ .gdarticlebody :where(.infobox, .navbox, .thumb, .tright, .tleft) {
8007
+ float: none !important;
8008
+ inline-size: auto !important;
8009
+ max-inline-size: 100% !important;
8010
+ margin-inline: 0 !important;
8011
+ }
8012
+
8013
+ .gdarticlebody .thumbinner {
8014
+ inline-size: 100% !important;
8015
+ max-inline-size: 100% !important;
8016
+ }
8017
+ }
8018
+
8019
+ @media (pointer: coarse) {
8020
+ .gddictname {
8021
+ min-block-size: 2.75rem;
8022
+ }
8023
+ }
8024
+ `, T = /* @__PURE__ */ new Set([
7899
8025
  "bres",
7900
8026
  "qrcx",
7901
8027
  "gico",
7902
8028
  "gdau",
7903
8029
  "gdvideo"
7904
- ]), de = {
8030
+ ]), se = {
7905
8031
  gdlookup: "lookup",
7906
8032
  bword: "lookup",
7907
8033
  entry: "lookup",
@@ -7916,8 +8042,8 @@ const T = /* @__PURE__ */ new Set([
7916
8042
  gdinternal: "unsupported",
7917
8043
  ankicard: "unsupported",
7918
8044
  ankisearch: "unsupported"
7919
- }, le = new Set(
7920
- Object.entries(de).filter(([, i]) => i === "unsupported").map(([i]) => i)
8045
+ }, ce = new Set(
8046
+ Object.entries(se).filter(([, i]) => i === "unsupported").map(([i]) => i)
7921
8047
  );
7922
8048
  function f(i) {
7923
8049
  try {
@@ -7929,10 +8055,10 @@ function f(i) {
7929
8055
  function I(i, e) {
7930
8056
  return `${i.replace(/\/+$/, "")}/${e.replace(/^\/+/, "")}`;
7931
8057
  }
7932
- function se(i) {
8058
+ function me(i) {
7933
8059
  return i.pathname.replace(/^\/+/, "").split("/").map((e) => encodeURIComponent(f(e))).join("/");
7934
8060
  }
7935
- function ce(i, e) {
8061
+ function pe(i, e) {
7936
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);
7937
8063
  }
7938
8064
  function S(i) {
@@ -7940,7 +8066,7 @@ function S(i) {
7940
8066
  if (e)
7941
8067
  return e.startsWith("/") && !e.startsWith("//") && /^[a-z][a-z\d+.-]*:/i.test(i.apiBaseUrl) ? new URL(e, i.apiBaseUrl).toString() : e;
7942
8068
  }
7943
- function m(i, e) {
8069
+ function p(i, e) {
7944
8070
  const o = A(i);
7945
8071
  if (o)
7946
8072
  return o;
@@ -7951,21 +8077,21 @@ function m(i, e) {
7951
8077
  t = new URL(i);
7952
8078
  } catch {
7953
8079
  const l = S(e);
7954
- return l ? ce(i, l) : i;
8080
+ return l ? pe(i, l) : i;
7955
8081
  }
7956
8082
  const n = t.protocol.slice(0, -1).toLowerCase();
7957
8083
  if (!T.has(n))
7958
8084
  return i;
7959
8085
  const a = t.hostname || e.dictionaryId;
7960
8086
  if (n === "gico")
7961
- return e.iconUrl ? m(e.iconUrl, {
8087
+ return e.iconUrl ? p(e.iconUrl, {
7962
8088
  ...e,
7963
8089
  iconUrl: void 0
7964
8090
  }) : A("qrc:///icons/document.png") ?? "";
7965
- const r = se(t), d = `${e.apiBaseUrl.replace(/\/+$/, "")}/dictionaries/${encodeURIComponent(a)}/resources`, p = I(S(e) ?? d, r);
7966
- return t.hash ? `${p}${t.hash}` : p;
8091
+ const r = me(t), d = `${e.apiBaseUrl.replace(/\/+$/, "")}/dictionaries/${encodeURIComponent(a)}/resources`, m = I(S(e) ?? d, r);
8092
+ return t.hash ? `${m}${t.hash}` : m;
7967
8093
  }
7968
- function me(i) {
8094
+ function ge(i) {
7969
8095
  const e = /^([a-z][a-z\d+.-]*):(.*)$/i.exec(i);
7970
8096
  if (!e)
7971
8097
  return;
@@ -7977,8 +8103,8 @@ function me(i) {
7977
8103
  const r = new URL(i);
7978
8104
  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);
7979
8105
  } catch {
7980
- const r = e[2]?.replace(/^\/{0,2}/, "") ?? "", [d, p] = r.split("#", 2), [l, w] = (d ?? "").split("?", 2);
7981
- t = l ?? "", n = new URLSearchParams(w ?? "").get("gdanchor") ?? (p || void 0);
8106
+ const r = e[2]?.replace(/^\/{0,2}/, "") ?? "", [d, m] = r.split("#", 2), [l, w] = (d ?? "").split("?", 2);
8107
+ t = l ?? "", n = new URLSearchParams(w ?? "").get("gdanchor") ?? (m || void 0);
7982
8108
  }
7983
8109
  return t = f(t.replace(/^\/+/, "")), t ? {
7984
8110
  kind: "lookup",
@@ -7993,22 +8119,22 @@ function D(i, e) {
7993
8119
  return { kind: "anchor", anchor: "" };
7994
8120
  if (o.startsWith("#"))
7995
8121
  return { kind: "anchor", anchor: f(o.slice(1)) };
7996
- const t = me(o);
8122
+ const t = ge(o);
7997
8123
  if (t)
7998
8124
  return t;
7999
8125
  const n = /^([a-z][a-z\d+.-]*):/i.exec(o)?.[1]?.toLowerCase();
8000
8126
  if (n === "javascript" || n === "vbscript" || n === "file" || n === "data")
8001
8127
  return { kind: "unsafe" };
8002
- if (n && le.has(n))
8128
+ if (n && ce.has(n))
8003
8129
  return { kind: "unsafe" };
8004
8130
  if (n && T.has(n))
8005
- return { kind: n === "gdau" ? "audio" : n === "gdvideo" ? "video" : "resource", url: m(o, e) };
8131
+ return { kind: n === "gdau" ? "audio" : n === "gdvideo" ? "video" : "resource", url: p(o, e) };
8006
8132
  if (o.startsWith("//") || n === "http" || n === "https" || n === "mailto" || n === "tel")
8007
8133
  return { kind: "external", url: o };
8008
8134
  if (n)
8009
8135
  return { kind: "unsafe" };
8010
8136
  if (o.startsWith("/"))
8011
- return { kind: "resource", url: m(o, e) };
8137
+ return { kind: "resource", url: p(o, e) };
8012
8138
  const [a, r] = o.split("#", 2);
8013
8139
  return a ? {
8014
8140
  kind: "lookup",
@@ -8016,11 +8142,11 @@ function D(i, e) {
8016
8142
  ...r ? { anchor: f(r) } : {}
8017
8143
  } : { kind: "anchor", anchor: f(r ?? "") };
8018
8144
  }
8019
- const pe = ["src", "poster", "data"];
8020
- function u(i) {
8145
+ const he = ["src", "poster", "data"];
8146
+ function x(i) {
8021
8147
  return /^(?:data:|blob:|https?:|#)/i.test(i);
8022
8148
  }
8023
- function ge(i, e, o) {
8149
+ function fe(i, e, o) {
8024
8150
  const t = [
8025
8151
  ["data-gd-audio", "audio"],
8026
8152
  ["data-gd-video", "video"],
@@ -8031,12 +8157,12 @@ function ge(i, e, o) {
8031
8157
  const d = i.getAttribute(a)?.trim();
8032
8158
  return {
8033
8159
  kind: r,
8034
- url: m(d || e, o)
8160
+ url: p(d || e, o)
8035
8161
  };
8036
8162
  }
8037
8163
  const n = i.getAttribute("data-gd-action")?.trim().toLowerCase();
8038
8164
  if (n === "audio" || n === "video" || n === "resource")
8039
- return { kind: n, url: m(e, o) };
8165
+ return { kind: n, url: p(e, o) };
8040
8166
  if (i.hasAttribute("data-gd-lookup") || n === "lookup") {
8041
8167
  const a = i.getAttribute("data-gd-lookup")?.trim();
8042
8168
  if (a && a !== "true" && a !== "1")
@@ -8050,7 +8176,7 @@ function ge(i, e, o) {
8050
8176
  if (n === "unsafe")
8051
8177
  return { kind: "unsafe" };
8052
8178
  }
8053
- function he(i, e, o) {
8179
+ function we(i, e, o) {
8054
8180
  switch (e.kind) {
8055
8181
  case "anchor":
8056
8182
  i.setAttribute(
@@ -8082,20 +8208,20 @@ function C(i, e) {
8082
8208
  /url\(\s*(["']?)([^"')]+)\1\s*\)/gi,
8083
8209
  (t, n, a) => {
8084
8210
  const r = a.trim();
8085
- return u(r) ? t : `url(${n}${m(r, e)}${n})`;
8211
+ return x(r) ? t : `url(${n}${p(r, e)}${n})`;
8086
8212
  }
8087
8213
  ).replace(
8088
8214
  /@import\s+(["'])([^"']+)\1/gi,
8089
- (t, n, a) => u(a) ? t : `@import ${n}${m(a, e)}${n}`
8215
+ (t, n, a) => x(a) ? t : `@import ${n}${p(a, e)}${n}`
8090
8216
  );
8091
8217
  }
8092
- function fe(i, e) {
8218
+ function be(i, e) {
8093
8219
  return i.split(/,\s+(?=[^,]+(?:\s+\d+(?:\.\d+)?[wx])?(?:,|$))/).map((o) => {
8094
8220
  const t = /^(\S+)([\s\S]*)$/.exec(o.trim());
8095
- return !t?.[1] || u(t[1]) ? o.trim() : `${m(t[1], e)}${t[2] ?? ""}`;
8221
+ return !t?.[1] || x(t[1]) ? o.trim() : `${p(t[1], e)}${t[2] ?? ""}`;
8096
8222
  }).join(", ");
8097
8223
  }
8098
- function we(i) {
8224
+ function ke(i) {
8099
8225
  if (!i.classList.contains("hidden_expand_opt"))
8100
8226
  return;
8101
8227
  const e = i.getAttribute("onclick") ?? "", o = /gdExpandOptPart\(\s*['"]([^'"]+)['"]\s*,\s*['"]([^'"]+)['"]\s*\)/.exec(
@@ -8103,7 +8229,7 @@ function we(i) {
8103
8229
  );
8104
8230
  o?.[1] && o[2] && (i.setAttribute("data-gd-expander", o[1]), i.setAttribute("data-gd-optional", o[2]));
8105
8231
  }
8106
- function be(i, e, o) {
8232
+ function ue(i, e, o) {
8107
8233
  if (typeof document > "u")
8108
8234
  throw new Error("Article rendering requires a browser document");
8109
8235
  const t = {
@@ -8116,37 +8242,37 @@ function be(i, e, o) {
8116
8242
  r.remove();
8117
8243
  }), o === "none" && a.querySelectorAll("script").forEach((r) => r.remove());
8118
8244
  for (const r of a.querySelectorAll("*")) {
8119
- if (we(r), o === "none")
8245
+ if (ke(r), o === "none")
8120
8246
  for (const l of [...r.attributes])
8121
8247
  (/^on/i.test(l.name) || l.name.toLowerCase() === "srcdoc") && r.removeAttribute(l.name);
8122
8248
  if (r instanceof HTMLAnchorElement || r.tagName === "AREA") {
8123
8249
  const l = r.getAttribute("href");
8124
- l !== null && he(
8250
+ l !== null && we(
8125
8251
  r,
8126
- ge(r, l, t) ?? D(l, t),
8252
+ fe(r, l, t) ?? D(l, t),
8127
8253
  i.dictionaryId
8128
8254
  );
8129
8255
  } else if (r.hasAttribute("href")) {
8130
8256
  const l = r.getAttribute("href") ?? "";
8131
- u(l) || r.setAttribute("href", m(l, t));
8257
+ x(l) || r.setAttribute("href", p(l, t));
8132
8258
  }
8133
- for (const l of pe) {
8259
+ for (const l of he) {
8134
8260
  const w = r.getAttribute(l);
8135
- w === null || u(w) || (/^(?:javascript|vbscript|file):/i.test(w) ? r.removeAttribute(l) : r.setAttribute(l, m(w, t)));
8261
+ w === null || x(w) || (/^(?:javascript|vbscript|file):/i.test(w) ? r.removeAttribute(l) : r.setAttribute(l, p(w, t)));
8136
8262
  }
8137
8263
  const d = r.getAttribute("srcset");
8138
- d && r.setAttribute("srcset", fe(d, t));
8139
- const p = r.getAttribute("style");
8140
- p && r.setAttribute(
8264
+ d && r.setAttribute("srcset", be(d, t));
8265
+ const m = r.getAttribute("style");
8266
+ m && r.setAttribute(
8141
8267
  "style",
8142
- C(p, t)
8268
+ C(m, t)
8143
8269
  );
8144
8270
  }
8145
8271
  for (const r of a.querySelectorAll("style"))
8146
8272
  r.textContent = C(r.textContent ?? "", t);
8147
8273
  return a.innerHTML;
8148
8274
  }
8149
- const ke = {
8275
+ const xe = {
8150
8276
  fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, Arial, sans-serif',
8151
8277
  textColor: "#222222",
8152
8278
  mutedTextColor: "#555555",
@@ -8160,8 +8286,8 @@ const ke = {
8160
8286
  selectionTextColor: "#ffffff",
8161
8287
  radius: "8px",
8162
8288
  spacing: "8px"
8163
- }, ue = {
8164
- fontFamily: ke.fontFamily,
8289
+ }, ye = {
8290
+ fontFamily: xe.fontFamily,
8165
8291
  textColor: "#edf1f5",
8166
8292
  mutedTextColor: "#aeb8c3",
8167
8293
  linkColor: "#79bfff",
@@ -8175,17 +8301,17 @@ const ke = {
8175
8301
  radius: "8px",
8176
8302
  spacing: "8px"
8177
8303
  };
8178
- function xe(i = "light") {
8304
+ function E(i = "light") {
8179
8305
  return i !== "auto" ? i : globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
8180
8306
  }
8181
8307
  function c(i, e) {
8182
8308
  return e === void 0 ? "" : `${i}:${e};`;
8183
8309
  }
8184
- function x(i) {
8310
+ function k(i) {
8185
8311
  return i.replace(/<\/style/gi, "<\\/style");
8186
8312
  }
8187
- function ye(i = {}) {
8188
- const e = xe(i.mode), o = i.tokens ?? {}, t = e === "dark" ? { ...ue, ...o } : o, n = [
8313
+ function ve(i = {}) {
8314
+ const e = E(i.mode), o = i.tokens ?? {}, t = e === "dark" ? { ...ye, ...o } : o, n = [
8189
8315
  c("--gd-font-family", t.fontFamily),
8190
8316
  c("--gd-text-color", t.textColor),
8191
8317
  c("--gd-muted-text-color", t.mutedTextColor),
@@ -8212,36 +8338,36 @@ function ye(i = {}) {
8212
8338
  t.selectionColor || t.selectionTextColor ? "::selection{background:var(--gd-selection-color,var(--selection-bg));color:var(--gd-selection-text-color,var(--selection-text));}" : "",
8213
8339
  t.radius ? ".gdarticle{border-radius:var(--gd-radius);}" : ""
8214
8340
  ].join("");
8215
- return x(
8341
+ return k(
8216
8342
  `:root{color-scheme:${e};${n}}${a}${i.cssText ?? ""}`
8217
8343
  );
8218
8344
  }
8219
8345
  function g(i) {
8220
8346
  return i.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
8221
8347
  }
8222
- function ve(i) {
8348
+ function _e(i) {
8223
8349
  return i.replace(
8224
8350
  /[^a-zA-Z0-9_-]/g,
8225
8351
  (e) => `_u${e.codePointAt(0)?.toString(16) ?? "0"}_`
8226
8352
  );
8227
8353
  }
8228
- function _e(i) {
8354
+ function ze(i) {
8229
8355
  return (i ?? "unknown").toLowerCase().replace(/[^a-z0-9_-]/g, "-");
8230
8356
  }
8231
- function ze(i, e) {
8232
- return i.iconUrl ? m(i.iconUrl, {
8357
+ function Ae(i, e) {
8358
+ return i.iconUrl ? p(i.iconUrl, {
8233
8359
  apiBaseUrl: e,
8234
8360
  dictionaryId: i.dictionaryId,
8235
8361
  ...i.resourceBaseUrl ? { resourceBaseUrl: i.resourceBaseUrl } : {}
8236
- }) : k["document.png"];
8362
+ }) : u["document.png"];
8237
8363
  }
8238
- function Ae(i, e, o) {
8239
- const t = g(i.dictionaryId), n = ve(i.dictionaryId), a = be(i, e, o), r = _e(i.sourceLanguage), d = g(i.targetLanguage ?? ""), p = g(ze(i, e));
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), d = g(i.targetLanguage ?? ""), m = g(Ae(i, e));
8240
8366
  return `
8241
8367
  <article class="gdarticle" id="gdfrom-${n}" data-gd-id="${t}">
8242
8368
  <gd-dict-header class="gddictname" id="gddictname-${n}"
8243
8369
  role="button" tabindex="0" aria-expanded="true" aria-controls="gd-${n}">
8244
- <span class="gddicticon"><img src="${p}" alt=""></span>
8370
+ <span class="gddicticon"><img src="${m}" alt=""></span>
8245
8371
  <span class="gdfromprefix">From </span>
8246
8372
  <span class="gddicttitle">${g(i.dictionaryName)}</span>
8247
8373
  <span class="collapse_expand_area" aria-hidden="true">
@@ -8254,7 +8380,7 @@ function Ae(i, e, o) {
8254
8380
  <div class="gdclear" aria-hidden="true"></div>
8255
8381
  <span class="gdarticleseparator"></span>`;
8256
8382
  }
8257
- function Se(i) {
8383
+ function Ce(i) {
8258
8384
  return i.length ? `<div class="gdstemmedsuggestion">
8259
8385
  <span class="gdstemmedsuggestion_head">Close words: </span>
8260
8386
  <span class="gdstemmedsuggestion_body">${i.map(
@@ -8262,14 +8388,15 @@ function Se(i) {
8262
8388
  ).join(", ")}</span>
8263
8389
  </div>` : "";
8264
8390
  }
8265
- function Ce(i) {
8391
+ function Te(i, e) {
8266
8392
  return `(function(){
8267
8393
  "use strict";
8268
8394
  const config=${JSON.stringify({
8269
8395
  namespace: "goldendict-web",
8270
8396
  instanceId: i,
8271
- expandOptIcon: k["expand_opt.svg"],
8272
- collapseOptIcon: k["collapse_opt.svg"]
8397
+ themeMode: e,
8398
+ expandOptIcon: u["expand_opt.svg"],
8399
+ collapseOptIcon: u["collapse_opt.svg"]
8273
8400
  }).replace(/<\//g, "<\\/")};
8274
8401
  const post=(type,detail={})=>parent.postMessage({
8275
8402
  namespace:config.namespace,
@@ -8279,6 +8406,27 @@ function Ce(i) {
8279
8406
  },"*");
8280
8407
  const articleOf=(target)=>target instanceof Element?target.closest(".gdarticle"):null;
8281
8408
  const articleId=(article)=>article?.getAttribute("data-gd-id")||"";
8409
+ const syncDictionaryTheme=()=>{
8410
+ if(document.documentElement.getAttribute("data-gd-theme")!==config.themeMode){
8411
+ document.documentElement.setAttribute("data-gd-theme",config.themeMode);
8412
+ }
8413
+ if(document.documentElement.getAttribute("data-darkreader-scheme")!==config.themeMode){
8414
+ document.documentElement.setAttribute("data-darkreader-scheme",config.themeMode);
8415
+ }
8416
+ document.querySelectorAll(".oaldpe").forEach((container)=>{
8417
+ if(container.getAttribute("data-theme")!==config.themeMode){
8418
+ container.setAttribute("data-theme",config.themeMode);
8419
+ }
8420
+ });
8421
+ };
8422
+ const themeObserver=new MutationObserver(syncDictionaryTheme);
8423
+ themeObserver.observe(document.documentElement,{
8424
+ subtree:true,
8425
+ childList:true,
8426
+ attributes:true,
8427
+ attributeFilter:["data-theme","data-darkreader-scheme"]
8428
+ });
8429
+ syncDictionaryTheme();
8282
8430
  const setActive=(article,notify=true)=>{
8283
8431
  if(!article)return;
8284
8432
  document.querySelector(".gdactivearticle")?.classList.remove("gdactivearticle");
@@ -8369,9 +8517,22 @@ function Ce(i) {
8369
8517
  const header=target.closest(".gddictname");
8370
8518
  if(header){event.preventDefault();toggleArticle(articleOf(header));}
8371
8519
  });
8372
- const requestSize=()=>requestAnimationFrame(()=>post("height",{
8373
- height:Math.max(document.body.scrollHeight,document.documentElement.scrollHeight)
8374
- }));
8520
+ let resizeFrame=0;
8521
+ let lastHeight=0;
8522
+ const requestSize=()=>{
8523
+ cancelAnimationFrame(resizeFrame);
8524
+ resizeFrame=requestAnimationFrame(()=>{
8525
+ resizeFrame=0;
8526
+ const height=Math.ceil(Math.max(
8527
+ document.body.scrollHeight,
8528
+ document.body.offsetHeight,
8529
+ document.body.getBoundingClientRect().height
8530
+ ));
8531
+ if(height===lastHeight)return;
8532
+ lastHeight=height;
8533
+ post("height",{height});
8534
+ });
8535
+ };
8375
8536
  addEventListener("message",(event)=>{
8376
8537
  const message=event.data;
8377
8538
  if(event.source!==parent||message?.namespace!==config.namespace||message?.instanceId!==config.instanceId)return;
@@ -8381,11 +8542,13 @@ function Ce(i) {
8381
8542
  article?.scrollIntoView({block:"start"});setActive(article,false);
8382
8543
  }
8383
8544
  });
8384
- new ResizeObserver(requestSize).observe(document.documentElement);
8545
+ const resizeObserver=new ResizeObserver(requestSize);
8546
+ resizeObserver.observe(document.body);
8547
+ addEventListener("resize",requestSize,{passive:true});
8385
8548
  addEventListener("load",()=>{requestSize();post("ready",{});});
8386
8549
  })();`;
8387
8550
  }
8388
- function Te(i, e) {
8551
+ function Ie(i, e) {
8389
8552
  const o = i === "none" ? `'nonce-${e}'` : "'unsafe-inline' 'unsafe-eval' data: blob: http: https:", t = i === "none" ? "'none'" : "http: https:";
8390
8553
  return [
8391
8554
  "default-src 'none'",
@@ -8401,24 +8564,25 @@ function Te(i, e) {
8401
8564
  "base-uri 'none'"
8402
8565
  ].join("; ");
8403
8566
  }
8404
- function Ie(i, e) {
8405
- const o = e.theme ?? {}, t = e.instanceId.replace(/[^a-zA-Z0-9_-]/g, ""), n = i.articles.map(
8406
- (d) => Ae(d, e.apiBaseUrl, e.scriptPolicy)
8407
- ).join(""), a = n ? `${n}<div class="empty-space" aria-hidden="true"></div>` : `<div class="gdnotfound"><p>No translation for <b>${g(i.word)}</b> was found.</p></div>`, r = o.brandName ? `${i.word} — ${o.brandName}` : i.word;
8567
+ function De(i, e) {
8568
+ const o = e.theme ?? {}, t = E(o.mode), n = e.instanceId.replace(/[^a-zA-Z0-9_-]/g, ""), a = i.articles.map(
8569
+ (m) => Se(m, e.apiBaseUrl, e.scriptPolicy)
8570
+ ).join(""), r = a ? `${a}<div class="empty-space" aria-hidden="true"></div>` : `<div class="gdnotfound"><p>No translation for <b>${g(i.word)}</b> was found.</p></div>`, d = o.brandName ? `${i.word} — ${o.brandName}` : i.word;
8408
8571
  return `<!doctype html>
8409
- <html><head>
8572
+ <html data-gd-theme="${t}" data-darkreader-scheme="${t}"><head>
8410
8573
  <meta charset="utf-8">
8411
8574
  <meta name="viewport" content="width=device-width,initial-scale=1">
8412
- <meta http-equiv="Content-Security-Policy" content="${g(Te(e.scriptPolicy, t))}">
8413
- <title>${g(r)}</title>
8414
- <style>${x(ne)}</style>
8415
- <style>${x(ae(o.preset))}</style>
8416
- <style>${ye(o)}</style>
8417
- <style media="print">${x(re)}</style>
8575
+ <meta http-equiv="Content-Security-Policy" content="${g(Ie(e.scriptPolicy, n))}">
8576
+ <title>${g(d)}</title>
8577
+ <style>${k(re)}</style>
8578
+ <style>${k(de(o.preset))}</style>
8579
+ <style data-gd-style="responsive">${k(le)}</style>
8580
+ <style>${ve(o)}</style>
8581
+ <style media="print">${k(ae)}</style>
8418
8582
  </head><body>
8419
- ${a}
8420
- ${Se(i.suggestions)}
8421
- <script nonce="${t}">${Ce(e.instanceId).replace(/<\/script/gi, "<\\/script")}<\/script>
8583
+ ${r}
8584
+ ${Ce(i.suggestions)}
8585
+ <script nonce="${n}">${Te(e.instanceId, t).replace(/<\/script/gi, "<\\/script")}<\/script>
8422
8586
  </body></html>`;
8423
8587
  }
8424
8588
  const b = {
@@ -8428,26 +8592,28 @@ const b = {
8428
8592
  mediaRequest: "goldendict-media-request",
8429
8593
  externalLink: "goldendict-external-link",
8430
8594
  stateChange: "goldendict-state-change"
8431
- }, De = `
8432
- :host{display:block;min-width:0;color:#222;font-family:system-ui,sans-serif}
8433
- .shell{position:relative;min-height:8rem;border-radius:var(--gd-host-radius,8px);overflow:hidden;background:var(--gd-host-background,#fff)}
8434
- .brand{display:flex;align-items:center;gap:.65rem;padding:.65rem .9rem;border-bottom:1px solid var(--gd-host-border,#e3e3e3);background:var(--gd-host-surface,#f7f9fb);font-weight:650}
8595
+ }, Ee = `
8596
+ :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}
8597
+ .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)}
8598
+ .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}
8435
8599
  .brand[hidden]{display:none}
8436
- .brand img{display:block;width:1.75rem;height:1.75rem;object-fit:contain}
8600
+ .brand img{display:block;flex:0 0 auto;width:1.75rem;height:1.75rem;object-fit:contain}
8437
8601
  .brand img[hidden]{display:none}
8602
+ .brand span{min-width:0;overflow-wrap:anywhere}
8438
8603
  .status{display:grid;place-items:center;min-height:8rem;padding:1.25rem;text-align:center;color:var(--gd-host-muted,#59636e)}
8439
8604
  .status[hidden]{display:none}
8440
8605
  .status[data-state="error"]{color:var(--gd-host-error,#a21d2d)}
8441
8606
  .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}
8442
- iframe{display:block;width:100%;min-height:8rem;border:0;background:transparent}
8607
+ iframe{display:block;box-sizing:border-box;width:100%;min-width:0;max-width:100%;min-height:8rem;border:0;background:transparent}
8443
8608
  iframe[hidden]{display:none}
8444
8609
  @keyframes spin{to{transform:rotate(360deg)}}
8610
+ @container goldendict-view (max-width:30rem){.brand{gap:.5rem;padding:.55rem .65rem}.status{padding:1rem .75rem}}
8445
8611
  @media (prefers-reduced-motion:reduce){.spinner{animation:none}}
8446
8612
  `;
8447
- function Ee() {
8613
+ function qe() {
8448
8614
  return globalThis.crypto?.randomUUID?.() ?? `gd-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
8449
8615
  }
8450
- function qe(i) {
8616
+ function Le(i) {
8451
8617
  return (i instanceof DOMException || i instanceof Error) && i.name === "AbortError";
8452
8618
  }
8453
8619
  class _ extends HTMLElement {
@@ -8458,7 +8624,7 @@ class _ extends HTMLElement {
8458
8624
  "theme-mode",
8459
8625
  "script-policy"
8460
8626
  ];
8461
- instanceId = Ee();
8627
+ instanceId = qe();
8462
8628
  frame;
8463
8629
  statusElement;
8464
8630
  brandElement;
@@ -8467,6 +8633,8 @@ class _ extends HTMLElement {
8467
8633
  clientValue;
8468
8634
  requestController;
8469
8635
  requestSequence = 0;
8636
+ renderSequence = 0;
8637
+ activeBridgeInstanceId;
8470
8638
  responseValue;
8471
8639
  themeValue = {};
8472
8640
  stateValue = "idle";
@@ -8475,7 +8643,7 @@ class _ extends HTMLElement {
8475
8643
  constructor() {
8476
8644
  super();
8477
8645
  const e = this.attachShadow({ mode: "open" });
8478
- e.innerHTML = `<style>${De}</style>
8646
+ e.innerHTML = `<style>${Ee}</style>
8479
8647
  <section class="shell" part="container">
8480
8648
  <div class="brand" part="brand" hidden>
8481
8649
  <img alt="" hidden><span></span>
@@ -8483,7 +8651,7 @@ class _ extends HTMLElement {
8483
8651
  <div class="status" part="status" role="status" aria-live="polite"></div>
8484
8652
  <iframe part="article" title="Dictionary article" sandbox="allow-scripts"
8485
8653
  referrerpolicy="no-referrer" hidden></iframe>
8486
- </section>`, this.frame = e.querySelector("iframe"), this.statusElement = e.querySelector(".status"), this.brandElement = e.querySelector(".brand"), this.brandImage = this.brandElement.querySelector("img"), this.brandText = this.brandElement.querySelector("span"), this.clientValue = new v({ baseUrl: this.apiBase }), this.frame.addEventListener("load", () => this.handleFrameLoaded()), this.updateBrand(), this.setState("idle");
8654
+ </section>`, this.frame = e.querySelector("iframe"), this.statusElement = e.querySelector(".status"), this.brandElement = e.querySelector(".brand"), this.brandImage = this.brandElement.querySelector("img"), this.brandText = this.brandElement.querySelector("span"), this.clientValue = new v({ baseUrl: this.apiBase }), this.updateBrand(), this.setState("idle");
8487
8655
  }
8488
8656
  connectedCallback() {
8489
8657
  globalThis.addEventListener("message", this.handleBridgeMessage);
@@ -8559,10 +8727,10 @@ class _ extends HTMLElement {
8559
8727
  return;
8560
8728
  this.setLookupResponse(r);
8561
8729
  } catch (r) {
8562
- if (n !== this.requestSequence || qe(r))
8730
+ if (n !== this.requestSequence || Le(r))
8563
8731
  return;
8564
8732
  const d = r instanceof Error ? r : new Error(String(r));
8565
- this.responseValue = void 0, this.frame.hidden = !0, this.setState("error", { word: t, error: d });
8733
+ this.responseValue = void 0, this.resetFrame(), this.setState("error", { word: t, error: d });
8566
8734
  } finally {
8567
8735
  n === this.requestSequence && (this.requestController = void 0);
8568
8736
  }
@@ -8571,21 +8739,37 @@ class _ extends HTMLElement {
8571
8739
  this.responseValue = e, this.renderResponse(e);
8572
8740
  }
8573
8741
  abort() {
8574
- this.requestController?.abort(), this.requestController = void 0;
8742
+ this.requestController?.abort(), this.requestController = void 0, this.renderSequence += 1, this.resetFrame();
8575
8743
  }
8576
8744
  clear() {
8577
- this.abort(), this.requestSequence += 1, this.responseValue = void 0, this.frame.removeAttribute("srcdoc"), this.frame.hidden = !0, this.setState("idle");
8745
+ this.abort(), this.requestSequence += 1, this.responseValue = void 0, this.setState("idle");
8578
8746
  }
8579
8747
  scrollToArticle(e) {
8580
8748
  this.postCommand({ type: "scroll-article", dictionaryId: e });
8581
8749
  }
8582
8750
  renderResponse(e) {
8583
- this.frame.style.height = "8rem", this.frame.srcdoc = Ie(e, {
8751
+ const o = ++this.renderSequence, t = `${this.instanceId}-${o}`;
8752
+ this.activeBridgeInstanceId = t;
8753
+ const n = this.replaceFrame(!1);
8754
+ n.title = e.word ? `Dictionary results for ${e.word}` : "Dictionary article";
8755
+ const a = De(e, {
8584
8756
  apiBaseUrl: this.clientValue.baseUrl,
8585
- instanceId: this.instanceId,
8757
+ instanceId: t,
8586
8758
  scriptPolicy: this.scriptPolicy,
8587
8759
  theme: this.themeValue
8588
- }), this.frame.title = e.word ? `Dictionary results for ${e.word}` : "Dictionary article", this.frame.hidden = !1, this.statusElement.hidden = !0;
8760
+ });
8761
+ requestAnimationFrame(() => {
8762
+ o !== this.renderSequence || n !== this.frame || (n.srcdoc = a, this.statusElement.hidden = !0);
8763
+ });
8764
+ }
8765
+ resetFrame() {
8766
+ this.activeBridgeInstanceId = void 0, this.replaceFrame(!0);
8767
+ }
8768
+ replaceFrame(e) {
8769
+ const o = this.frame, t = this.ownerDocument.createElement("iframe");
8770
+ return t.setAttribute("part", "article"), t.title = "Dictionary article", t.setAttribute("sandbox", "allow-scripts"), t.referrerPolicy = "no-referrer", t.style.height = "8rem", t.hidden = e, t.addEventListener("load", () => {
8771
+ this.frame === t && t.hasAttribute("srcdoc") && this.handleFrameLoaded();
8772
+ }), o.replaceWith(t), this.frame = t, t.offsetWidth, t;
8589
8773
  }
8590
8774
  handleFrameLoaded() {
8591
8775
  this.responseValue && (this.setState(
@@ -8597,7 +8781,7 @@ class _ extends HTMLElement {
8597
8781
  if (e.source !== this.frame.contentWindow)
8598
8782
  return;
8599
8783
  const o = e.data;
8600
- if (o.namespace !== "goldendict-web" || o.instanceId !== this.instanceId || !o.type)
8784
+ if (o.namespace !== "goldendict-web" || o.instanceId !== this.activeBridgeInstanceId || !o.type)
8601
8785
  return;
8602
8786
  const t = o.detail ?? {};
8603
8787
  switch (o.type) {
@@ -8606,7 +8790,7 @@ class _ extends HTMLElement {
8606
8790
  break;
8607
8791
  case "height": {
8608
8792
  const n = Number(t.height);
8609
- Number.isFinite(n) && n > 0 && (this.frame.style.height = `${Math.min(Math.max(n, 128), 1e5)}px`);
8793
+ Number.isFinite(n) && n > 0 && (this.frame.style.height = `${Math.min(Math.max(n, 128), 1e5)}px`, this.handleFrameLoaded());
8610
8794
  break;
8611
8795
  }
8612
8796
  case "lookup":
@@ -8682,10 +8866,10 @@ class _ extends HTMLElement {
8682
8866
  });
8683
8867
  }
8684
8868
  postCommand(e) {
8685
- this.frame.contentWindow?.postMessage(
8869
+ this.activeBridgeInstanceId && this.frame.contentWindow?.postMessage(
8686
8870
  {
8687
8871
  namespace: "goldendict-web",
8688
- instanceId: this.instanceId,
8872
+ instanceId: this.activeBridgeInstanceId,
8689
8873
  ...e
8690
8874
  },
8691
8875
  "*"
@@ -8701,26 +8885,26 @@ class _ extends HTMLElement {
8701
8885
  return this.dispatchEvent(n), n;
8702
8886
  }
8703
8887
  }
8704
- function Le(i = "goldendict-view") {
8888
+ function Be(i = "goldendict-view") {
8705
8889
  if (!globalThis.customElements)
8706
8890
  return _;
8707
8891
  const e = globalThis.customElements.get(i);
8708
8892
  return e || (globalThis.customElements.define(i, _), _);
8709
8893
  }
8710
- Le();
8894
+ Be();
8711
8895
  export {
8712
- ue as DARK_THEME_TOKENS,
8713
- E as DictionaryApiError,
8896
+ ye as DARK_THEME_TOKENS,
8897
+ q as DictionaryApiError,
8714
8898
  v as DictionaryClient,
8715
8899
  b as GOLDENDICT_EVENTS,
8716
- de as GOLDENDICT_SCHEME_SUPPORT,
8900
+ se as GOLDENDICT_SCHEME_SUPPORT,
8717
8901
  _ as GoldenDictView,
8718
- ke as LIGHT_THEME_TOKENS,
8902
+ xe as LIGHT_THEME_TOKENS,
8719
8903
  D as classifyArticleLink,
8720
- Le as defineGoldendictView,
8721
- x as escapeStyleText,
8722
- m as resolveResourceUrl,
8723
- xe as resolveThemeMode,
8724
- ye as themeToCss
8904
+ Be as defineGoldendictView,
8905
+ k as escapeStyleText,
8906
+ p as resolveResourceUrl,
8907
+ E as resolveThemeMode,
8908
+ ve as themeToCss
8725
8909
  };
8726
8910
  //# sourceMappingURL=index.js.map