@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/README.md CHANGED
@@ -69,7 +69,7 @@ The public API includes:
69
69
  - `GoldenDictView` and `defineGoldendictView` for framework-independent use.
70
70
  - `GoldenDictTheme`, light/dark token presets, and `themeToCss` for branding.
71
71
  - `GOLDENDICT_EVENTS` for lookup, active article, collapse, media, external-link,
72
- and state notifications.
72
+ dictionary-resource failure, and state notifications.
73
73
  - Resource/link helpers for hosts that need to inspect GoldenDict URLs.
74
74
 
75
75
  Dictionary scripts are removed by default (`scriptPolicy = "none"`). The
@@ -90,6 +90,22 @@ Because the iframe has an opaque origin, dictionary XHR/fetch requests send
90
90
  compatibility mode is enabled. Classic script element loads do not grant the
91
91
  dictionary access to the host document.
92
92
 
93
+ Failed external dictionary stylesheets and scripts are not treated as a
94
+ successful render. The component keeps the fallback article visible, changes
95
+ `state` to `"error"`, exposes the failures through `view.resourceErrors`, and
96
+ emits `GOLDENDICT_EVENTS.resourceError` with the failed URL and resource type:
97
+
98
+ ```ts
99
+ view.addEventListener(GOLDENDICT_EVENTS.resourceError, (event) => {
100
+ const { detail } = event as CustomEvent;
101
+ console.error("Dictionary sidecar failed", detail);
102
+ });
103
+ ```
104
+
105
+ This diagnoses top-level `<link rel="stylesheet">` and `<script src>` failures;
106
+ font/image failures and exceptions thrown inside dictionary code remain normal
107
+ browser console/network diagnostics.
108
+
93
109
  Run the package demo from the workspace root with `npm run dev`. It discovers
94
110
  the dictionaries loaded from the backend's configured local paths at startup.
95
111
 
@@ -1,5 +1,5 @@
1
1
  import { DictionaryClient } from "../client/dictionary-client";
2
- import type { ArticleLayoutMode, DictionaryClientOptions, GoldenDictTheme, LookupResponse, ScriptPolicy, ViewState } from "../types";
2
+ import type { ArticleLayoutMode, DictionaryResourceErrorEventDetail, DictionaryClientOptions, GoldenDictTheme, LookupResponse, ScriptPolicy, ViewState } from "../types";
3
3
  export declare class GoldenDictView extends HTMLElement {
4
4
  static readonly observedAttributes: string[];
5
5
  readonly instanceId: string;
@@ -16,6 +16,8 @@ export declare class GoldenDictView extends HTMLElement {
16
16
  private responseValue?;
17
17
  private themeValue;
18
18
  private stateValue;
19
+ private errorValue?;
20
+ private resourceErrorsValue;
19
21
  private dictionaryIdsValue;
20
22
  private pendingAnchor?;
21
23
  constructor();
@@ -36,6 +38,10 @@ export declare class GoldenDictView extends HTMLElement {
36
38
  set dictionaryIds(value: readonly string[]);
37
39
  get state(): ViewState;
38
40
  get response(): LookupResponse | undefined;
41
+ /** The current request or article-resource error, if `state` is `"error"`. */
42
+ get error(): Error | undefined;
43
+ /** Dictionary-authored stylesheets or scripts that failed in this render. */
44
+ get resourceErrors(): readonly DictionaryResourceErrorEventDetail[];
39
45
  configureClient(options: DictionaryClientOptions): void;
40
46
  lookup(word: string, dictionaryIds?: readonly string[]): Promise<void>;
41
47
  setLookupResponse(response: LookupResponse): void;
@@ -47,6 +53,8 @@ export declare class GoldenDictView extends HTMLElement {
47
53
  private replaceFrame;
48
54
  private handleFrameLoaded;
49
55
  private readonly handleBridgeMessage;
56
+ private handleResourceErrorMessage;
57
+ private resourceError;
50
58
  private handleLookupMessage;
51
59
  private handleMediaMessage;
52
60
  private handleExternalLink;
@@ -1 +1 @@
1
- {"version":3,"file":"goldendict-view.d.ts","sourceRoot":"","sources":["../../src/element/goldendict-view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,OAAO,KAAK,EAEV,iBAAiB,EAEjB,uBAAuB,EAEvB,eAAe,EAEf,cAAc,EAEd,YAAY,EACZ,SAAS,EAEV,MAAM,UAAU,CAAC;AAwClB,qBAAa,cAAe,SAAQ,WAAW;IAC7C,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAOhC;IAEF,QAAQ,CAAC,UAAU,SAAoB;IACvC,OAAO,CAAC,KAAK,CAAoB;IACjC,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