@panda-lingo/goldendict 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,6 +20,48 @@ await view.lookup("example");
20
20
  Importing the package registers `<goldendict-view>` automatically. Call
21
21
  `defineGoldendictView("my-dictionary-view")` when a custom tag name is useful.
22
22
 
23
+ The component is responsive by default. It fills the width of its containing
24
+ layout, uses container-aware host chrome, and remeasures article height whenever
25
+ its iframe reflows. A separate browser override layer constrains legacy
26
+ fixed-width dictionary media, makes wide tables and preformatted text locally
27
+ scrollable, unwraps common floated wiki panels on narrow screens, and keeps
28
+ article headers usable with coarse pointers. The pinned GoldenDict-ng CSS stays
29
+ unchanged so upstream updates remain straightforward.
30
+
31
+ For GoldenDict-compatible article geometry, select the fidelity layout. This
32
+ omits the browser override layer so the upstream body margin, content-box model,
33
+ dictionary header flow, and dictionary-authored CSS cascade remain intact.
34
+ Script permission is independent: a dictionary may require both fidelity layout
35
+ and sandboxed sidecar JavaScript.
36
+
37
+ ```ts
38
+ view.layoutMode = "fidelity";
39
+ view.scriptPolicy = "sandboxed";
40
+ ```
41
+
42
+ The default `layoutMode` is `"responsive"`; the bundled demo deliberately uses
43
+ `"fidelity"` so it can be compared directly with GoldenDict-ng. Consumers can
44
+ also set `layout-mode="fidelity"` on the custom element.
45
+
46
+ Compare at the same CSS viewport, device scale, and GoldenDict zoom: those host
47
+ browser settings still affect physical pixel size and line wrapping.
48
+
49
+ ```css
50
+ .dictionary-column {
51
+ min-width: 0;
52
+ }
53
+
54
+ goldendict-view {
55
+ width: 100%;
56
+ max-width: 72rem;
57
+ margin-inline: auto;
58
+ }
59
+ ```
60
+
61
+ Consumer `theme.cssText` is emitted after the responsive layer and can override
62
+ it when a particular dictionary requires different behavior. Set
63
+ `--gd-responsive-gutter` there to customize the article's fluid inner spacing.
64
+
23
65
  The public API includes:
24
66
 
25
67
  - `DictionaryClient` for dictionary listing and lookup, plus the backend's
@@ -35,6 +77,12 @@ explicit `"sandboxed"` policy retains them inside the iframe, which never gets
35
77
  `allow-same-origin`. Lookup, media, and external-link events are cancelable so a
36
78
  host application can replace the default navigation behavior.
37
79
 
80
+ The bundled demo deliberately selects `"sandboxed"` scripts and `"fidelity"`
81
+ layout for locally mounted dictionaries so script-dependent formats such as
82
+ OALDPE render with their GoldenDict typography, geometry, and interactions.
83
+ These demo choices do not change the component defaults (`"none"` scripts and
84
+ `"responsive"` layout) for consumers.
85
+
38
86
  In sandboxed mode, external sidecars such as `bres://.../Dictionary-UI.js` are
39
87
  routed through the article's `resourceBaseUrl` without changing filename case.
40
88
  Because the iframe has an opaque origin, dictionary XHR/fetch requests send
@@ -1,9 +1,9 @@
1
1
  import { DictionaryClient } from "../client/dictionary-client";
2
- import type { DictionaryClientOptions, GoldenDictTheme, LookupResponse, ScriptPolicy, ViewState } from "../types";
2
+ import type { ArticleLayoutMode, 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;
6
- private readonly frame;
6
+ private frame;
7
7
  private readonly statusElement;
8
8
  private readonly brandElement;
9
9
  private readonly brandImage;
@@ -11,6 +11,8 @@ export declare class GoldenDictView extends HTMLElement {
11
11
  private clientValue;
12
12
  private requestController?;
13
13
  private requestSequence;
14
+ private renderSequence;
15
+ private activeBridgeInstanceId?;
14
16
  private responseValue?;
15
17
  private themeValue;
16
18
  private stateValue;
@@ -28,6 +30,8 @@ export declare class GoldenDictView extends HTMLElement {
28
30
  set theme(value: GoldenDictTheme);
29
31
  get scriptPolicy(): ScriptPolicy;
30
32
  set scriptPolicy(value: ScriptPolicy);
33
+ get layoutMode(): ArticleLayoutMode;
34
+ set layoutMode(value: ArticleLayoutMode);
31
35
  get dictionaryIds(): readonly string[];
32
36
  set dictionaryIds(value: readonly string[]);
33
37
  get state(): ViewState;
@@ -39,6 +43,8 @@ export declare class GoldenDictView extends HTMLElement {
39
43
  clear(): void;
40
44
  scrollToArticle(dictionaryId: string): void;
41
45
  private renderResponse;
46
+ private resetFrame;
47
+ private replaceFrame;
42
48
  private handleFrameLoaded;
43
49
  private readonly handleBridgeMessage;
44
50
  private handleLookupMessage;
@@ -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,EAGV,uBAAuB,EAEvB,eAAe,EAEf,cAAc,EAEd,YAAY,EACZ,SAAS,EAEV,MAAM,UAAU,CAAC;AAsClB,qBAAa,cAAe,SAAQ,WAAW;IAC7C,MAAM,CAAC,QAAQ,CAAC,kBAAkB,WAMhC;IAEF,QAAQ,CAAC,UAAU,SAAoB;IACvC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAoB;IAC1C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAC/C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAiB;IAC9C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkB;IAC5C,OAAO,CAAC,WAAW,CAAmB;IACtC,OAAO,CAAC,iBAAiB,CAAC,CAAkB;IAC5C,OAAO,CAAC,eAAe,CAAK;IAC5B,OAAO,CAAC,aAAa,CAAC,CAAiB;IACvC,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,kBAAkB,CAAgB;IAC1C,OAAO,CAAC,aAAa,CAAC,CAAS;;IAyB/B,iBAAiB,IAAI,IAAI;IAQzB,oBAAoB,IAAI,IAAI;IAK5B,wBAAwB,CACtB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,QAAQ,EAAE,MAAM,GAAG,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