Skip to content

Commit 377b386

Browse files
authored
Webpub proto fixes (#166)
1 parent 87fdae3 commit 377b386

File tree

5 files changed

+107
-74
lines changed

5 files changed

+107
-74
lines changed

navigator/CHANGELOG.MD

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.2.2] - 2025-10-30
9+
10+
### Added
11+
12+
- Guard `WebPubSettings` assignment on `displayTransformability`
13+
14+
### Fixed
15+
16+
- Corrects `isEffective` check in `WebPubPreferencesEditor`
17+
818
## [2.2.1] - 2025-10-28
919

1020
### Added

navigator/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@readium/navigator",
3-
"version": "2.2.1",
3+
"version": "2.2.2",
44
"type": "module",
55
"description": "Next generation SDK for publications in Web Apps",
66
"author": "readium",

navigator/src/webpub/WebPubNavigator.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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";
22
import { VisualNavigator, VisualNavigatorViewport, ProgressionRange } from "../Navigator";
33
import { Configurable } from "../preferences/Configurable";
44
import { WebPubFramePoolManager } from "./WebPubFramePoolManager";
55
import { BasicTextSelection, CommsEventKey, FrameClickEvent, ModuleLibrary, ModuleName, WebPubModules } from "@readium/navigator-html-injectables";
66
import * as path from "path-browserify";
7+
import { WebPubFrameManager } from "./WebPubFrameManager";
8+
79
import { ManagerEventKey } from "../epub/EpubNavigator";
810
import { WebPubCSS } from "./css/WebPubCSS";
911
import { WebUserProperties } from "./css/Properties";
@@ -12,7 +14,6 @@ import { IWebPubDefaults, WebPubDefaults } from "./preferences/WebPubDefaults";
1214
import { WebPubSettings } from "./preferences/WebPubSettings";
1315
import { IPreferencesEditor } from "../preferences/PreferencesEditor";
1416
import { WebPubPreferencesEditor } from "./preferences/WebPubPreferencesEditor";
15-
1617
export interface WebPubNavigatorConfiguration {
1718
preferences: IWebPubPreferences;
1819
defaults: IWebPubDefaults;
@@ -71,7 +72,7 @@ export class WebPubNavigator extends VisualNavigator implements Configurable<Web
7172
// Initialize preference system
7273
this._preferences = new WebPubPreferences(configuration.preferences);
7374
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);
7576
this._css = new WebPubCSS({
7677
userProperties: new WebUserProperties({ zoom: this._settings.zoom })
7778
});
@@ -115,7 +116,7 @@ export class WebPubNavigator extends VisualNavigator implements Configurable<Web
115116
}
116117

117118
private async applyPreferences() {
118-
this._settings = new WebPubSettings(this._preferences, this._defaults);
119+
this._settings = new WebPubSettings(this._preferences, this._defaults, this.hasDisplayTransformability);
119120

120121
if (this._preferencesEditor !== null) {
121122
this._preferencesEditor = new WebPubPreferencesEditor(this._preferences, this.settings, this.pub.metadata);
@@ -146,6 +147,20 @@ export class WebPubNavigator extends VisualNavigator implements Configurable<Web
146147
this.framePool.setCSSProperties(properties);
147148
}
148149

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+
149164
public eventListener(key: CommsEventKey | ManagerEventKey, data: unknown) {
150165
switch (key) {
151166
case "_pong":

navigator/src/webpub/preferences/WebPubPreferencesEditor.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,17 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
3333
this.preferences[key] = value;
3434
}
3535

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+
3642
get fontFamily(): Preference<string> {
3743
return new Preference<string>({
3844
initialValue: this.preferences.fontFamily,
3945
effectiveValue: this.settings.fontFamily || null,
40-
isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
46+
isEffective: this.isDisplayTransformable,
4147
onChange: (newValue: string | null | undefined) => {
4248
this.updatePreference("fontFamily", newValue || null);
4349
}
@@ -48,7 +54,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
4854
return new RangePreference<number>({
4955
initialValue: this.preferences.fontWeight,
5056
effectiveValue: this.settings.fontWeight || 400,
51-
isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
57+
isEffective: this.isDisplayTransformable,
5258
onChange: (newValue: number | null | undefined) => {
5359
this.updatePreference("fontWeight", newValue || null);
5460
},
@@ -61,7 +67,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
6167
return new BooleanPreference({
6268
initialValue: this.preferences.hyphens,
6369
effectiveValue: this.settings.hyphens || false,
64-
isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
70+
isEffective: this.isDisplayTransformable,
6571
onChange: (newValue: boolean | null | undefined) => {
6672
this.updatePreference("hyphens", newValue || null);
6773
}
@@ -72,7 +78,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
7278
return new RangePreference<number>({
7379
initialValue: this.preferences.letterSpacing,
7480
effectiveValue: this.settings.letterSpacing || 0,
75-
isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
81+
isEffective: this.isDisplayTransformable,
7682
onChange: (newValue: number | null | undefined) => {
7783
this.updatePreference("letterSpacing", newValue || null);
7884
},
@@ -85,7 +91,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
8591
return new BooleanPreference({
8692
initialValue: this.preferences.ligatures,
8793
effectiveValue: this.settings.ligatures || true,
88-
isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
94+
isEffective: this.isDisplayTransformable,
8995
onChange: (newValue: boolean | null | undefined) => {
9096
this.updatePreference("ligatures", newValue || null);
9197
}
@@ -96,7 +102,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
96102
return new RangePreference<number>({
97103
initialValue: this.preferences.lineHeight,
98104
effectiveValue: this.settings.lineHeight,
99-
isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
105+
isEffective: this.isDisplayTransformable,
100106
onChange: (newValue: number | null | undefined) => {
101107
this.updatePreference("lineHeight", newValue || null);
102108
},
@@ -109,7 +115,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
109115
return new BooleanPreference({
110116
initialValue: this.preferences.noRuby,
111117
effectiveValue: this.settings.noRuby || false,
112-
isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
118+
isEffective: this.isDisplayTransformable,
113119
onChange: (newValue: boolean | null | undefined) => {
114120
this.updatePreference("noRuby", newValue || null);
115121
}
@@ -120,7 +126,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
120126
return new RangePreference<number>({
121127
initialValue: this.preferences.paragraphIndent,
122128
effectiveValue: this.settings.paragraphIndent || 0,
123-
isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
129+
isEffective: this.isDisplayTransformable,
124130
onChange: (newValue: number | null | undefined) => {
125131
this.updatePreference("paragraphIndent", newValue || null);
126132
},
@@ -133,7 +139,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
133139
return new RangePreference<number>({
134140
initialValue: this.preferences.paragraphSpacing,
135141
effectiveValue: this.settings.paragraphSpacing || 0,
136-
isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
142+
isEffective: this.isDisplayTransformable,
137143
onChange: (newValue: number | null | undefined) => {
138144
this.updatePreference("paragraphSpacing", newValue || null);
139145
},
@@ -146,7 +152,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
146152
return new EnumPreference<TextAlignment>({
147153
initialValue: this.preferences.textAlign,
148154
effectiveValue: this.settings.textAlign || TextAlignment.start,
149-
isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
155+
isEffective: this.isDisplayTransformable,
150156
onChange: (newValue: TextAlignment | null | undefined) => {
151157
this.updatePreference("textAlign", newValue || null);
152158
},
@@ -158,7 +164,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
158164
return new BooleanPreference({
159165
initialValue: this.preferences.textNormalization,
160166
effectiveValue: this.settings.textNormalization || false,
161-
isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
167+
isEffective: this.isDisplayTransformable,
162168
onChange: (newValue: boolean | null | undefined) => {
163169
this.updatePreference("textNormalization", newValue || null);
164170
}
@@ -169,7 +175,7 @@ export class WebPubPreferencesEditor implements IPreferencesEditor {
169175
return new RangePreference<number>({
170176
initialValue: this.preferences.wordSpacing,
171177
effectiveValue: this.settings.wordSpacing || 0,
172-
isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
178+
isEffective: this.isDisplayTransformable,
173179
onChange: (newValue: number | null | undefined) => {
174180
this.updatePreference("wordSpacing", newValue || null);
175181
},

navigator/src/webpub/preferences/WebPubSettings.ts

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -20,65 +20,67 @@ export interface IWebPubSettings {
2020
}
2121

2222
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;
3535
zoom: number | null;
3636

37-
constructor(preferences: WebPubPreferences, defaults: WebPubDefaults) {
38-
this.fontFamily = preferences.fontFamily || defaults.fontFamily || null;
39-
this.fontWeight = preferences.fontWeight !== undefined
40-
? preferences.fontWeight
41-
: defaults.fontWeight !== undefined
42-
? defaults.fontWeight
43-
: null;
44-
this.hyphens = typeof preferences.hyphens === "boolean"
45-
? preferences.hyphens
46-
: defaults.hyphens ?? null;
47-
this.letterSpacing = preferences.letterSpacing !== undefined
48-
? preferences.letterSpacing
49-
: defaults.letterSpacing !== undefined
50-
? defaults.letterSpacing
51-
: null;
52-
this.ligatures = typeof preferences.ligatures === "boolean"
53-
? preferences.ligatures
54-
: defaults.ligatures ?? null;
55-
this.lineHeight = preferences.lineHeight !== undefined
56-
? preferences.lineHeight
57-
: defaults.lineHeight !== undefined
58-
? defaults.lineHeight
59-
: null;
60-
this.noRuby = typeof preferences.noRuby === "boolean"
61-
? preferences.noRuby
62-
: defaults.noRuby ?? null;
63-
this.paragraphIndent = preferences.paragraphIndent !== undefined
64-
? preferences.paragraphIndent
65-
: defaults.paragraphIndent !== undefined
66-
? defaults.paragraphIndent
67-
: null;
68-
this.paragraphSpacing = preferences.paragraphSpacing !== undefined
69-
? preferences.paragraphSpacing
70-
: defaults.paragraphSpacing !== undefined
71-
? defaults.paragraphSpacing
72-
: null;
73-
this.textAlign = preferences.textAlign || defaults.textAlign || null;
74-
this.textNormalization = typeof preferences.textNormalization === "boolean"
75-
? preferences.textNormalization
76-
: defaults.textNormalization ?? null;
77-
this.wordSpacing = preferences.wordSpacing !== undefined
78-
? preferences.wordSpacing
79-
: defaults.wordSpacing !== undefined
80-
? defaults.wordSpacing
81-
: null;
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+
}
8284
this.zoom = preferences.zoom !== undefined
8385
? preferences.zoom
8486
: defaults.zoom !== undefined

0 commit comments

Comments
 (0)