@readium/navigator 2.2.1 → 2.2.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/dist/index.js +651 -634
- package/dist/index.umd.cjs +17 -17
- package/package.json +1 -1
- package/src/webpub/WebPubNavigator.ts +19 -4
- package/src/webpub/preferences/WebPubPreferencesEditor.ts +18 -12
- package/src/webpub/preferences/WebPubSettings.ts +59 -57
- package/types/src/webpub/WebPubNavigator.d.ts +7 -0
- package/types/src/webpub/preferences/WebPubPreferencesEditor.d.ts +1 -0
- package/types/src/webpub/preferences/WebPubSettings.d.ts +1 -1
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { Link, Locator, Publication, ReadingProgression, LocatorLocations } from "@readium/shared";
|
|
1
|
+
import { Feature, Link, Locator, Publication, ReadingProgression, LocatorLocations } from "@readium/shared";
|
|
2
2
|
import { VisualNavigator, VisualNavigatorViewport, ProgressionRange } from "../Navigator";
|
|
3
3
|
import { Configurable } from "../preferences/Configurable";
|
|
4
4
|
import { WebPubFramePoolManager } from "./WebPubFramePoolManager";
|
|
5
5
|
import { BasicTextSelection, CommsEventKey, FrameClickEvent, ModuleLibrary, ModuleName, WebPubModules } from "@readium/navigator-html-injectables";
|
|
6
6
|
import * as path from "path-browserify";
|
|
7
|
+
import { WebPubFrameManager } from "./WebPubFrameManager";
|
|
8
|
+
|
|
7
9
|
import { ManagerEventKey } from "../epub/EpubNavigator";
|
|
8
10
|
import { WebPubCSS } from "./css/WebPubCSS";
|
|
9
11
|
import { WebUserProperties } from "./css/Properties";
|
|
@@ -12,7 +14,6 @@ import { IWebPubDefaults, WebPubDefaults } from "./preferences/WebPubDefaults";
|
|
|
12
14
|
import { WebPubSettings } from "./preferences/WebPubSettings";
|
|
13
15
|
import { IPreferencesEditor } from "../preferences/PreferencesEditor";
|
|
14
16
|
import { WebPubPreferencesEditor } from "./preferences/WebPubPreferencesEditor";
|
|
15
|
-
|
|
16
17
|
export interface WebPubNavigatorConfiguration {
|
|
17
18
|
preferences: IWebPubPreferences;
|
|
18
19
|
defaults: IWebPubDefaults;
|
|
@@ -71,7 +72,7 @@ export class WebPubNavigator extends VisualNavigator implements Configurable<Web
|
|
|
71
72
|
// Initialize preference system
|
|
72
73
|
this._preferences = new WebPubPreferences(configuration.preferences);
|
|
73
74
|
this._defaults = new WebPubDefaults(configuration.defaults);
|
|
74
|
-
this._settings = new WebPubSettings(this._preferences, this._defaults);
|
|
75
|
+
this._settings = new WebPubSettings(this._preferences, this._defaults, this.hasDisplayTransformability);
|
|
75
76
|
this._css = new WebPubCSS({
|
|
76
77
|
userProperties: new WebUserProperties({ zoom: this._settings.zoom })
|
|
77
78
|
});
|
|
@@ -115,7 +116,7 @@ export class WebPubNavigator extends VisualNavigator implements Configurable<Web
|
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
private async applyPreferences() {
|
|
118
|
-
this._settings = new WebPubSettings(this._preferences, this._defaults);
|
|
119
|
+
this._settings = new WebPubSettings(this._preferences, this._defaults, this.hasDisplayTransformability);
|
|
119
120
|
|
|
120
121
|
if (this._preferencesEditor !== null) {
|
|
121
122
|
this._preferencesEditor = new WebPubPreferencesEditor(this._preferences, this.settings, this.pub.metadata);
|
|
@@ -146,6 +147,20 @@ export class WebPubNavigator extends VisualNavigator implements Configurable<Web
|
|
|
146
147
|
this.framePool.setCSSProperties(properties);
|
|
147
148
|
}
|
|
148
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Exposed to the public to compensate for lack of implemented readium conveniences
|
|
152
|
+
* TODO remove when settings management is incorporated
|
|
153
|
+
*/
|
|
154
|
+
public get _cframes(): (WebPubFrameManager | undefined)[] {
|
|
155
|
+
return this.framePool.currentFrames;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private get hasDisplayTransformability(): boolean {
|
|
159
|
+
return this.pub.metadata?.accessibility?.feature?.some(
|
|
160
|
+
f => f.value === Feature.DISPLAY_TRANSFORMABILITY.value
|
|
161
|
+
) ?? false;
|
|
162
|
+
}
|
|
163
|
+
|
|
149
164
|
public eventListener(key: CommsEventKey | ManagerEventKey, data: unknown) {
|
|
150
165
|
switch (key) {
|
|
151
166
|
case "_pong":
|
|
@@ -33,11 +33,17 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
|
|
|
33
33
|
this.preferences[key] = value;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
private get isDisplayTransformable(): boolean {
|
|
37
|
+
return this.metadata?.accessibility?.feature?.some(
|
|
38
|
+
f => f.value === Feature.DISPLAY_TRANSFORMABILITY.value
|
|
39
|
+
) ?? false; // Default to false if no metadata
|
|
40
|
+
}
|
|
41
|
+
|
|
36
42
|
get fontFamily(): Preference<string> {
|
|
37
43
|
return new Preference<string>({
|
|
38
44
|
initialValue: this.preferences.fontFamily,
|
|
39
45
|
effectiveValue: this.settings.fontFamily || null,
|
|
40
|
-
isEffective: this.
|
|
46
|
+
isEffective: this.isDisplayTransformable,
|
|
41
47
|
onChange: (newValue: string | null | undefined) => {
|
|
42
48
|
this.updatePreference("fontFamily", newValue || null);
|
|
43
49
|
}
|
|
@@ -48,7 +54,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
|
|
|
48
54
|
return new RangePreference<number>({
|
|
49
55
|
initialValue: this.preferences.fontWeight,
|
|
50
56
|
effectiveValue: this.settings.fontWeight || 400,
|
|
51
|
-
isEffective: this.
|
|
57
|
+
isEffective: this.isDisplayTransformable,
|
|
52
58
|
onChange: (newValue: number | null | undefined) => {
|
|
53
59
|
this.updatePreference("fontWeight", newValue || null);
|
|
54
60
|
},
|
|
@@ -61,7 +67,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
|
|
|
61
67
|
return new BooleanPreference({
|
|
62
68
|
initialValue: this.preferences.hyphens,
|
|
63
69
|
effectiveValue: this.settings.hyphens || false,
|
|
64
|
-
isEffective: this.
|
|
70
|
+
isEffective: this.isDisplayTransformable,
|
|
65
71
|
onChange: (newValue: boolean | null | undefined) => {
|
|
66
72
|
this.updatePreference("hyphens", newValue || null);
|
|
67
73
|
}
|
|
@@ -72,7 +78,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
|
|
|
72
78
|
return new RangePreference<number>({
|
|
73
79
|
initialValue: this.preferences.letterSpacing,
|
|
74
80
|
effectiveValue: this.settings.letterSpacing || 0,
|
|
75
|
-
isEffective: this.
|
|
81
|
+
isEffective: this.isDisplayTransformable,
|
|
76
82
|
onChange: (newValue: number | null | undefined) => {
|
|
77
83
|
this.updatePreference("letterSpacing", newValue || null);
|
|
78
84
|
},
|
|
@@ -85,7 +91,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
|
|
|
85
91
|
return new BooleanPreference({
|
|
86
92
|
initialValue: this.preferences.ligatures,
|
|
87
93
|
effectiveValue: this.settings.ligatures || true,
|
|
88
|
-
isEffective: this.
|
|
94
|
+
isEffective: this.isDisplayTransformable,
|
|
89
95
|
onChange: (newValue: boolean | null | undefined) => {
|
|
90
96
|
this.updatePreference("ligatures", newValue || null);
|
|
91
97
|
}
|
|
@@ -96,7 +102,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
|
|
|
96
102
|
return new RangePreference<number>({
|
|
97
103
|
initialValue: this.preferences.lineHeight,
|
|
98
104
|
effectiveValue: this.settings.lineHeight,
|
|
99
|
-
isEffective: this.
|
|
105
|
+
isEffective: this.isDisplayTransformable,
|
|
100
106
|
onChange: (newValue: number | null | undefined) => {
|
|
101
107
|
this.updatePreference("lineHeight", newValue || null);
|
|
102
108
|
},
|
|
@@ -109,7 +115,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
|
|
|
109
115
|
return new BooleanPreference({
|
|
110
116
|
initialValue: this.preferences.noRuby,
|
|
111
117
|
effectiveValue: this.settings.noRuby || false,
|
|
112
|
-
isEffective: this.
|
|
118
|
+
isEffective: this.isDisplayTransformable,
|
|
113
119
|
onChange: (newValue: boolean | null | undefined) => {
|
|
114
120
|
this.updatePreference("noRuby", newValue || null);
|
|
115
121
|
}
|
|
@@ -120,7 +126,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
|
|
|
120
126
|
return new RangePreference<number>({
|
|
121
127
|
initialValue: this.preferences.paragraphIndent,
|
|
122
128
|
effectiveValue: this.settings.paragraphIndent || 0,
|
|
123
|
-
isEffective: this.
|
|
129
|
+
isEffective: this.isDisplayTransformable,
|
|
124
130
|
onChange: (newValue: number | null | undefined) => {
|
|
125
131
|
this.updatePreference("paragraphIndent", newValue || null);
|
|
126
132
|
},
|
|
@@ -133,7 +139,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
|
|
|
133
139
|
return new RangePreference<number>({
|
|
134
140
|
initialValue: this.preferences.paragraphSpacing,
|
|
135
141
|
effectiveValue: this.settings.paragraphSpacing || 0,
|
|
136
|
-
isEffective: this.
|
|
142
|
+
isEffective: this.isDisplayTransformable,
|
|
137
143
|
onChange: (newValue: number | null | undefined) => {
|
|
138
144
|
this.updatePreference("paragraphSpacing", newValue || null);
|
|
139
145
|
},
|
|
@@ -146,7 +152,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
|
|
|
146
152
|
return new EnumPreference<TextAlignment>({
|
|
147
153
|
initialValue: this.preferences.textAlign,
|
|
148
154
|
effectiveValue: this.settings.textAlign || TextAlignment.start,
|
|
149
|
-
isEffective: this.
|
|
155
|
+
isEffective: this.isDisplayTransformable,
|
|
150
156
|
onChange: (newValue: TextAlignment | null | undefined) => {
|
|
151
157
|
this.updatePreference("textAlign", newValue || null);
|
|
152
158
|
},
|
|
@@ -158,7 +164,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
|
|
|
158
164
|
return new BooleanPreference({
|
|
159
165
|
initialValue: this.preferences.textNormalization,
|
|
160
166
|
effectiveValue: this.settings.textNormalization || false,
|
|
161
|
-
isEffective: this.
|
|
167
|
+
isEffective: this.isDisplayTransformable,
|
|
162
168
|
onChange: (newValue: boolean | null | undefined) => {
|
|
163
169
|
this.updatePreference("textNormalization", newValue || null);
|
|
164
170
|
}
|
|
@@ -169,7 +175,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
|
|
|
169
175
|
return new RangePreference<number>({
|
|
170
176
|
initialValue: this.preferences.wordSpacing,
|
|
171
177
|
effectiveValue: this.settings.wordSpacing || 0,
|
|
172
|
-
isEffective: this.
|
|
178
|
+
isEffective: this.isDisplayTransformable,
|
|
173
179
|
onChange: (newValue: number | null | undefined) => {
|
|
174
180
|
this.updatePreference("wordSpacing", newValue || null);
|
|
175
181
|
},
|
|
@@ -20,65 +20,67 @@ export interface IWebPubSettings {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export class WebPubSettings implements ConfigurableSettings {
|
|
23
|
-
fontFamily: string | null;
|
|
24
|
-
fontWeight: number | null;
|
|
25
|
-
hyphens: boolean | null;
|
|
26
|
-
letterSpacing: number | null;
|
|
27
|
-
ligatures: boolean | null;
|
|
28
|
-
lineHeight: number | null;
|
|
29
|
-
noRuby: boolean | null;
|
|
30
|
-
paragraphIndent: number | null;
|
|
31
|
-
paragraphSpacing: number | null;
|
|
32
|
-
textAlign: TextAlignment | null;
|
|
33
|
-
textNormalization: boolean | null;
|
|
34
|
-
wordSpacing: number | null;
|
|
23
|
+
fontFamily: string | null = null;
|
|
24
|
+
fontWeight: number | null = null;
|
|
25
|
+
hyphens: boolean | null = null;
|
|
26
|
+
letterSpacing: number | null = null;
|
|
27
|
+
ligatures: boolean | null = null;
|
|
28
|
+
lineHeight: number | null = null;
|
|
29
|
+
noRuby: boolean | null = null;
|
|
30
|
+
paragraphIndent: number | null = null;
|
|
31
|
+
paragraphSpacing: number | null = null;
|
|
32
|
+
textAlign: TextAlignment | null = null;
|
|
33
|
+
textNormalization: boolean | null = null;
|
|
34
|
+
wordSpacing: number | null = null;
|
|
35
35
|
zoom: number | null;
|
|
36
36
|
|
|
37
|
-
constructor(preferences: WebPubPreferences, defaults: WebPubDefaults) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
37
|
+
constructor(preferences: WebPubPreferences, defaults: WebPubDefaults, hasDisplayTransformability: boolean) {
|
|
38
|
+
if (hasDisplayTransformability) {
|
|
39
|
+
this.fontFamily = preferences.fontFamily || defaults.fontFamily || null;
|
|
40
|
+
this.fontWeight = preferences.fontWeight !== undefined
|
|
41
|
+
? preferences.fontWeight
|
|
42
|
+
: defaults.fontWeight !== undefined
|
|
43
|
+
? defaults.fontWeight
|
|
44
|
+
: null;
|
|
45
|
+
this.hyphens = typeof preferences.hyphens === "boolean"
|
|
46
|
+
? preferences.hyphens
|
|
47
|
+
: defaults.hyphens ?? null;
|
|
48
|
+
this.letterSpacing = preferences.letterSpacing !== undefined
|
|
49
|
+
? preferences.letterSpacing
|
|
50
|
+
: defaults.letterSpacing !== undefined
|
|
51
|
+
? defaults.letterSpacing
|
|
52
|
+
: null;
|
|
53
|
+
this.ligatures = typeof preferences.ligatures === "boolean"
|
|
54
|
+
? preferences.ligatures
|
|
55
|
+
: defaults.ligatures ?? null;
|
|
56
|
+
this.lineHeight = preferences.lineHeight !== undefined
|
|
57
|
+
? preferences.lineHeight
|
|
58
|
+
: defaults.lineHeight !== undefined
|
|
59
|
+
? defaults.lineHeight
|
|
60
|
+
: null;
|
|
61
|
+
this.noRuby = typeof preferences.noRuby === "boolean"
|
|
62
|
+
? preferences.noRuby
|
|
63
|
+
: defaults.noRuby ?? null;
|
|
64
|
+
this.paragraphIndent = preferences.paragraphIndent !== undefined
|
|
65
|
+
? preferences.paragraphIndent
|
|
66
|
+
: defaults.paragraphIndent !== undefined
|
|
67
|
+
? defaults.paragraphIndent
|
|
68
|
+
: null;
|
|
69
|
+
this.paragraphSpacing = preferences.paragraphSpacing !== undefined
|
|
70
|
+
? preferences.paragraphSpacing
|
|
71
|
+
: defaults.paragraphSpacing !== undefined
|
|
72
|
+
? defaults.paragraphSpacing
|
|
73
|
+
: null;
|
|
74
|
+
this.textAlign = preferences.textAlign || defaults.textAlign || null;
|
|
75
|
+
this.textNormalization = typeof preferences.textNormalization === "boolean"
|
|
76
|
+
? preferences.textNormalization
|
|
77
|
+
: defaults.textNormalization ?? null;
|
|
78
|
+
this.wordSpacing = preferences.wordSpacing !== undefined
|
|
79
|
+
? preferences.wordSpacing
|
|
80
|
+
: defaults.wordSpacing !== undefined
|
|
81
|
+
? defaults.wordSpacing
|
|
82
|
+
: null;
|
|
83
|
+
}
|
|
82
84
|
this.zoom = preferences.zoom !== undefined
|
|
83
85
|
? preferences.zoom
|
|
84
86
|
: defaults.zoom !== undefined
|
|
@@ -2,6 +2,7 @@ import { Link, Locator, Publication, ReadingProgression } from "@readium/shared"
|
|
|
2
2
|
import { VisualNavigator, VisualNavigatorViewport } from "../Navigator";
|
|
3
3
|
import { Configurable } from "../preferences/Configurable";
|
|
4
4
|
import { BasicTextSelection, CommsEventKey, FrameClickEvent } from "@readium/navigator-html-injectables";
|
|
5
|
+
import { WebPubFrameManager } from "./WebPubFrameManager";
|
|
5
6
|
import { ManagerEventKey } from "../epub/EpubNavigator";
|
|
6
7
|
import { IWebPubPreferences, WebPubPreferences } from "./preferences/WebPubPreferences";
|
|
7
8
|
import { IWebPubDefaults } from "./preferences/WebPubDefaults";
|
|
@@ -44,6 +45,12 @@ export declare class WebPubNavigator extends VisualNavigator implements Configur
|
|
|
44
45
|
private updateCSS;
|
|
45
46
|
private compileCSSProperties;
|
|
46
47
|
private commitCSS;
|
|
48
|
+
/**
|
|
49
|
+
* Exposed to the public to compensate for lack of implemented readium conveniences
|
|
50
|
+
* TODO remove when settings management is incorporated
|
|
51
|
+
*/
|
|
52
|
+
get _cframes(): (WebPubFrameManager | undefined)[];
|
|
53
|
+
private get hasDisplayTransformability();
|
|
47
54
|
eventListener(key: CommsEventKey | ManagerEventKey, data: unknown): void;
|
|
48
55
|
private determineModules;
|
|
49
56
|
private attachListener;
|
|
@@ -11,6 +11,7 @@ export declare class WebPubPreferencesEditor implements IPreferencesEditor {
|
|
|
11
11
|
constructor(initialPreferences: WebPubPreferences, settings: WebPubSettings, metadata: Metadata);
|
|
12
12
|
clear(): void;
|
|
13
13
|
private updatePreference;
|
|
14
|
+
private get isDisplayTransformable();
|
|
14
15
|
get fontFamily(): Preference<string>;
|
|
15
16
|
get fontWeight(): RangePreference<number>;
|
|
16
17
|
get hyphens(): BooleanPreference;
|
|
@@ -31,5 +31,5 @@ export declare class WebPubSettings implements ConfigurableSettings {
|
|
|
31
31
|
textNormalization: boolean | null;
|
|
32
32
|
wordSpacing: number | null;
|
|
33
33
|
zoom: number | null;
|
|
34
|
-
constructor(preferences: WebPubPreferences, defaults: WebPubDefaults);
|
|
34
|
+
constructor(preferences: WebPubPreferences, defaults: WebPubDefaults, hasDisplayTransformability: boolean);
|
|
35
35
|
}
|