@readium/navigator 2.2.0 → 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 +1912 -1330
- package/dist/index.umd.cjs +218 -17
- package/package.json +1 -1
- package/src/css/Properties.ts +47 -0
- package/src/css/index.ts +1 -0
- package/src/epub/css/Properties.ts +10 -48
- package/src/epub/preferences/EpubDefaults.ts +1 -1
- package/src/epub/preferences/EpubPreferences.ts +1 -1
- package/src/epub/preferences/EpubPreferencesEditor.ts +30 -23
- package/src/index.ts +2 -1
- package/src/preferences/Types.ts +40 -0
- package/src/{epub/preferences → preferences}/guards.ts +5 -6
- package/src/preferences/index.ts +2 -1
- package/src/webpub/WebPubBlobBuilder.ts +26 -4
- package/src/webpub/WebPubFrameManager.ts +16 -0
- package/src/webpub/WebPubFramePoolManager.ts +49 -2
- package/src/webpub/WebPubNavigator.ts +103 -11
- package/src/webpub/css/Properties.ts +71 -0
- package/src/webpub/css/WebPubCSS.ts +42 -0
- package/src/webpub/css/WebPubStylesheet.ts +204 -0
- package/src/webpub/css/index.ts +3 -0
- package/src/webpub/index.ts +3 -1
- package/src/webpub/preferences/WebPubDefaults.ts +61 -0
- package/src/webpub/preferences/WebPubPreferences.ts +88 -0
- package/src/webpub/preferences/WebPubPreferencesEditor.ts +199 -0
- package/src/webpub/preferences/WebPubSettings.ts +90 -0
- package/src/webpub/preferences/index.ts +4 -0
- package/types/src/css/Properties.d.ts +20 -0
- package/types/src/css/index.d.ts +1 -0
- package/types/src/epub/css/Properties.d.ts +1 -21
- package/types/src/index.d.ts +1 -0
- package/types/src/preferences/Types.d.ts +8 -0
- package/types/src/preferences/guards.d.ts +9 -0
- package/types/src/preferences/index.d.ts +1 -0
- package/types/src/webpub/WebPubBlobBuilder.d.ts +5 -1
- package/types/src/webpub/WebPubFrameManager.d.ts +4 -0
- package/types/src/webpub/WebPubFramePoolManager.d.ts +8 -1
- package/types/src/webpub/WebPubNavigator.d.ts +30 -3
- package/types/src/webpub/css/Properties.d.ts +36 -0
- package/types/src/webpub/css/WebPubCSS.d.ts +10 -0
- package/types/src/webpub/css/WebPubStylesheet.d.ts +1 -0
- package/types/src/webpub/css/index.d.ts +3 -0
- package/types/src/webpub/index.d.ts +2 -0
- package/types/src/webpub/preferences/WebPubDefaults.d.ts +32 -0
- package/types/src/webpub/preferences/WebPubPreferences.d.ts +36 -0
- package/types/src/webpub/preferences/WebPubPreferencesEditor.d.ts +28 -0
- package/types/src/webpub/preferences/WebPubSettings.d.ts +35 -0
- package/types/src/webpub/preferences/index.d.ts +4 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { Feature, Metadata } from "@readium/shared";
|
|
2
|
+
|
|
3
|
+
import { IPreferencesEditor } from "../../preferences/PreferencesEditor";
|
|
4
|
+
import { WebPubPreferences } from "./WebPubPreferences";
|
|
5
|
+
import { WebPubSettings } from "./WebPubSettings";
|
|
6
|
+
import { BooleanPreference, EnumPreference, Preference, RangePreference } from "../../preferences/Preference";
|
|
7
|
+
import {
|
|
8
|
+
fontWeightRangeConfig,
|
|
9
|
+
letterSpacingRangeConfig,
|
|
10
|
+
lineHeightRangeConfig,
|
|
11
|
+
paragraphIndentRangeConfig,
|
|
12
|
+
paragraphSpacingRangeConfig,
|
|
13
|
+
TextAlignment,
|
|
14
|
+
wordSpacingRangeConfig,
|
|
15
|
+
zoomRangeConfig
|
|
16
|
+
} from "../../preferences/Types";
|
|
17
|
+
export class WebPubPreferencesEditor implements IPreferencesEditor {
|
|
18
|
+
preferences: WebPubPreferences;
|
|
19
|
+
private settings: WebPubSettings;
|
|
20
|
+
private metadata: Metadata | null;
|
|
21
|
+
|
|
22
|
+
constructor(initialPreferences: WebPubPreferences, settings: WebPubSettings, metadata: Metadata) {
|
|
23
|
+
this.preferences = initialPreferences;
|
|
24
|
+
this.settings = settings;
|
|
25
|
+
this.metadata = metadata;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
clear() {
|
|
29
|
+
this.preferences = new WebPubPreferences({});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private updatePreference<K extends keyof WebPubPreferences>(key: K, value: WebPubPreferences[K]) {
|
|
33
|
+
this.preferences[key] = value;
|
|
34
|
+
}
|
|
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
|
+
|
|
42
|
+
get fontFamily(): Preference<string> {
|
|
43
|
+
return new Preference<string>({
|
|
44
|
+
initialValue: this.preferences.fontFamily,
|
|
45
|
+
effectiveValue: this.settings.fontFamily || null,
|
|
46
|
+
isEffective: this.isDisplayTransformable,
|
|
47
|
+
onChange: (newValue: string | null | undefined) => {
|
|
48
|
+
this.updatePreference("fontFamily", newValue || null);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get fontWeight(): RangePreference<number> {
|
|
54
|
+
return new RangePreference<number>({
|
|
55
|
+
initialValue: this.preferences.fontWeight,
|
|
56
|
+
effectiveValue: this.settings.fontWeight || 400,
|
|
57
|
+
isEffective: this.isDisplayTransformable,
|
|
58
|
+
onChange: (newValue: number | null | undefined) => {
|
|
59
|
+
this.updatePreference("fontWeight", newValue || null);
|
|
60
|
+
},
|
|
61
|
+
supportedRange: fontWeightRangeConfig.range,
|
|
62
|
+
step: fontWeightRangeConfig.step
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
get hyphens(): BooleanPreference {
|
|
67
|
+
return new BooleanPreference({
|
|
68
|
+
initialValue: this.preferences.hyphens,
|
|
69
|
+
effectiveValue: this.settings.hyphens || false,
|
|
70
|
+
isEffective: this.isDisplayTransformable,
|
|
71
|
+
onChange: (newValue: boolean | null | undefined) => {
|
|
72
|
+
this.updatePreference("hyphens", newValue || null);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get letterSpacing(): RangePreference<number> {
|
|
78
|
+
return new RangePreference<number>({
|
|
79
|
+
initialValue: this.preferences.letterSpacing,
|
|
80
|
+
effectiveValue: this.settings.letterSpacing || 0,
|
|
81
|
+
isEffective: this.isDisplayTransformable,
|
|
82
|
+
onChange: (newValue: number | null | undefined) => {
|
|
83
|
+
this.updatePreference("letterSpacing", newValue || null);
|
|
84
|
+
},
|
|
85
|
+
supportedRange: letterSpacingRangeConfig.range,
|
|
86
|
+
step: letterSpacingRangeConfig.step
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
get ligatures(): BooleanPreference {
|
|
91
|
+
return new BooleanPreference({
|
|
92
|
+
initialValue: this.preferences.ligatures,
|
|
93
|
+
effectiveValue: this.settings.ligatures || true,
|
|
94
|
+
isEffective: this.isDisplayTransformable,
|
|
95
|
+
onChange: (newValue: boolean | null | undefined) => {
|
|
96
|
+
this.updatePreference("ligatures", newValue || null);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
get lineHeight(): RangePreference<number> {
|
|
102
|
+
return new RangePreference<number>({
|
|
103
|
+
initialValue: this.preferences.lineHeight,
|
|
104
|
+
effectiveValue: this.settings.lineHeight,
|
|
105
|
+
isEffective: this.isDisplayTransformable,
|
|
106
|
+
onChange: (newValue: number | null | undefined) => {
|
|
107
|
+
this.updatePreference("lineHeight", newValue || null);
|
|
108
|
+
},
|
|
109
|
+
supportedRange: lineHeightRangeConfig.range,
|
|
110
|
+
step: lineHeightRangeConfig.step
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
get noRuby(): BooleanPreference {
|
|
115
|
+
return new BooleanPreference({
|
|
116
|
+
initialValue: this.preferences.noRuby,
|
|
117
|
+
effectiveValue: this.settings.noRuby || false,
|
|
118
|
+
isEffective: this.isDisplayTransformable,
|
|
119
|
+
onChange: (newValue: boolean | null | undefined) => {
|
|
120
|
+
this.updatePreference("noRuby", newValue || null);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
get paragraphIndent(): RangePreference<number> {
|
|
126
|
+
return new RangePreference<number>({
|
|
127
|
+
initialValue: this.preferences.paragraphIndent,
|
|
128
|
+
effectiveValue: this.settings.paragraphIndent || 0,
|
|
129
|
+
isEffective: this.isDisplayTransformable,
|
|
130
|
+
onChange: (newValue: number | null | undefined) => {
|
|
131
|
+
this.updatePreference("paragraphIndent", newValue || null);
|
|
132
|
+
},
|
|
133
|
+
supportedRange: paragraphIndentRangeConfig.range,
|
|
134
|
+
step: paragraphIndentRangeConfig.step
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
get paragraphSpacing(): RangePreference<number> {
|
|
139
|
+
return new RangePreference<number>({
|
|
140
|
+
initialValue: this.preferences.paragraphSpacing,
|
|
141
|
+
effectiveValue: this.settings.paragraphSpacing || 0,
|
|
142
|
+
isEffective: this.isDisplayTransformable,
|
|
143
|
+
onChange: (newValue: number | null | undefined) => {
|
|
144
|
+
this.updatePreference("paragraphSpacing", newValue || null);
|
|
145
|
+
},
|
|
146
|
+
supportedRange: paragraphSpacingRangeConfig.range,
|
|
147
|
+
step: paragraphSpacingRangeConfig.step
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
get textAlign(): EnumPreference<TextAlignment> {
|
|
152
|
+
return new EnumPreference<TextAlignment>({
|
|
153
|
+
initialValue: this.preferences.textAlign,
|
|
154
|
+
effectiveValue: this.settings.textAlign || TextAlignment.start,
|
|
155
|
+
isEffective: this.isDisplayTransformable,
|
|
156
|
+
onChange: (newValue: TextAlignment | null | undefined) => {
|
|
157
|
+
this.updatePreference("textAlign", newValue || null);
|
|
158
|
+
},
|
|
159
|
+
supportedValues: Object.values(TextAlignment)
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
get textNormalization(): BooleanPreference {
|
|
164
|
+
return new BooleanPreference({
|
|
165
|
+
initialValue: this.preferences.textNormalization,
|
|
166
|
+
effectiveValue: this.settings.textNormalization || false,
|
|
167
|
+
isEffective: this.isDisplayTransformable,
|
|
168
|
+
onChange: (newValue: boolean | null | undefined) => {
|
|
169
|
+
this.updatePreference("textNormalization", newValue || null);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
get wordSpacing(): RangePreference<number> {
|
|
175
|
+
return new RangePreference<number>({
|
|
176
|
+
initialValue: this.preferences.wordSpacing,
|
|
177
|
+
effectiveValue: this.settings.wordSpacing || 0,
|
|
178
|
+
isEffective: this.isDisplayTransformable,
|
|
179
|
+
onChange: (newValue: number | null | undefined) => {
|
|
180
|
+
this.updatePreference("wordSpacing", newValue || null);
|
|
181
|
+
},
|
|
182
|
+
supportedRange: wordSpacingRangeConfig.range,
|
|
183
|
+
step: wordSpacingRangeConfig.step
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
get zoom(): RangePreference<number> {
|
|
188
|
+
return new RangePreference<number>({
|
|
189
|
+
initialValue: this.preferences.zoom,
|
|
190
|
+
effectiveValue: this.settings.zoom || 1,
|
|
191
|
+
isEffective: CSS.supports("zoom", "1") ?? false,
|
|
192
|
+
onChange: (newValue: number | null | undefined) => {
|
|
193
|
+
this.updatePreference("zoom", newValue || null);
|
|
194
|
+
},
|
|
195
|
+
supportedRange: zoomRangeConfig.range,
|
|
196
|
+
step: zoomRangeConfig.step
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ConfigurableSettings } from "../../preferences/Configurable";
|
|
2
|
+
import { TextAlignment } from "../../preferences/Types";
|
|
3
|
+
import { WebPubDefaults } from "./WebPubDefaults";
|
|
4
|
+
import { WebPubPreferences } from "./WebPubPreferences";
|
|
5
|
+
|
|
6
|
+
export interface IWebPubSettings {
|
|
7
|
+
fontFamily?: string | null,
|
|
8
|
+
fontWeight?: number | null,
|
|
9
|
+
hyphens?: boolean | null,
|
|
10
|
+
letterSpacing?: number | null,
|
|
11
|
+
ligatures?: boolean | null,
|
|
12
|
+
lineHeight?: number | null,
|
|
13
|
+
noRuby?: boolean | null,
|
|
14
|
+
paragraphIndent?: number | null,
|
|
15
|
+
paragraphSpacing?: number | null,
|
|
16
|
+
textAlign?: TextAlignment | null,
|
|
17
|
+
textNormalization?: boolean | null,
|
|
18
|
+
wordSpacing?: number | null,
|
|
19
|
+
zoom?: number | null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class WebPubSettings implements ConfigurableSettings {
|
|
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
|
+
zoom: number | null;
|
|
36
|
+
|
|
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
|
+
}
|
|
84
|
+
this.zoom = preferences.zoom !== undefined
|
|
85
|
+
? preferences.zoom
|
|
86
|
+
: defaults.zoom !== undefined
|
|
87
|
+
? defaults.zoom
|
|
88
|
+
: null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type BodyHyphens = "auto" | "none";
|
|
2
|
+
export type BoxSizing = "content-box" | "border-box";
|
|
3
|
+
export type FontOpticalSizing = "auto" | "none";
|
|
4
|
+
export type FontWidth = "ultra-condensed" | "extra-condensed" | "condensed" | "semi-condensed" | "normal" | "semi-expanded" | "expanded" | "extra-expanded" | "ultra-expanded" | number;
|
|
5
|
+
export type Ligatures = "common-ligatures" | "none";
|
|
6
|
+
export type TypeScale = 1 | 1.067 | 1.125 | 1.2 | 1.25 | 1.333 | 1.414 | 1.5 | 1.618;
|
|
7
|
+
export type View = "paged" | "scroll";
|
|
8
|
+
export declare abstract class Properties {
|
|
9
|
+
constructor();
|
|
10
|
+
protected toFlag(name: string): string;
|
|
11
|
+
protected toUnitless(value: number): string;
|
|
12
|
+
protected toPercentage(value: number, ratio?: boolean): string;
|
|
13
|
+
protected toVw(value: number): string;
|
|
14
|
+
protected toVh(value: number): string;
|
|
15
|
+
protected toPx(value: number): string;
|
|
16
|
+
protected toRem(value: number): string;
|
|
17
|
+
abstract toCSSProperties(): {
|
|
18
|
+
[key: string]: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Properties";
|
|
@@ -1,24 +1,5 @@
|
|
|
1
1
|
import { TextAlignment } from "../../preferences/Types";
|
|
2
|
-
|
|
3
|
-
export type BoxSizing = "content-box" | "border-box";
|
|
4
|
-
export type FontOpticalSizing = "auto" | "none";
|
|
5
|
-
export type FontWidth = "ultra-condensed" | "extra-condensed" | "condensed" | "semi-condensed" | "normal" | "semi-expanded" | "expanded" | "extra-expanded" | "ultra-expanded" | number;
|
|
6
|
-
export type Ligatures = "common-ligatures" | "none";
|
|
7
|
-
export type TypeScale = 1 | 1.067 | 1.125 | 1.2 | 1.25 | 1.333 | 1.414 | 1.5 | 1.618;
|
|
8
|
-
export type View = "paged" | "scroll";
|
|
9
|
-
declare abstract class Properties {
|
|
10
|
-
constructor();
|
|
11
|
-
protected toFlag(name: string): string;
|
|
12
|
-
protected toUnitless(value: number): string;
|
|
13
|
-
protected toPercentage(value: number, ratio?: boolean): string;
|
|
14
|
-
protected toVw(value: number): string;
|
|
15
|
-
protected toVh(value: number): string;
|
|
16
|
-
protected toPx(value: number): string;
|
|
17
|
-
protected toRem(value: number): string;
|
|
18
|
-
abstract toCSSProperties(): {
|
|
19
|
-
[key: string]: string;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
2
|
+
import { BodyHyphens, BoxSizing, FontOpticalSizing, FontWidth, Ligatures, Properties, TypeScale, View } from "../../css/Properties";
|
|
22
3
|
export interface IUserProperties {
|
|
23
4
|
advancedSettings?: boolean | null;
|
|
24
5
|
a11yNormalize?: boolean | null;
|
|
@@ -178,4 +159,3 @@ export declare class RSProperties extends Properties {
|
|
|
178
159
|
[key: string]: string;
|
|
179
160
|
};
|
|
180
161
|
}
|
|
181
|
-
export {};
|
package/types/src/index.d.ts
CHANGED
|
@@ -8,6 +8,14 @@ export type RangeConfig = {
|
|
|
8
8
|
range: [number, number];
|
|
9
9
|
step: number;
|
|
10
10
|
};
|
|
11
|
+
export declare const filterRangeConfig: RangeConfig;
|
|
11
12
|
export declare const fontSizeRangeConfig: RangeConfig;
|
|
12
13
|
export declare const fontWeightRangeConfig: RangeConfig;
|
|
13
14
|
export declare const fontWidthRangeConfig: RangeConfig;
|
|
15
|
+
export declare const letterSpacingRangeConfig: RangeConfig;
|
|
16
|
+
export declare const lineHeightRangeConfig: RangeConfig;
|
|
17
|
+
export declare const lineLengthRangeConfig: RangeConfig;
|
|
18
|
+
export declare const paragraphIndentRangeConfig: RangeConfig;
|
|
19
|
+
export declare const paragraphSpacingRangeConfig: RangeConfig;
|
|
20
|
+
export declare const wordSpacingRangeConfig: RangeConfig;
|
|
21
|
+
export declare const zoomRangeConfig: RangeConfig;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function ensureLessThanOrEqual<T extends number | null | undefined>(value: T, compareTo: T): T | undefined;
|
|
2
|
+
export declare function ensureMoreThanOrEqual<T extends number | null | undefined>(value: T, compareTo: T): T | undefined;
|
|
3
|
+
export declare function ensureString(value: string | null | undefined): string | null | undefined;
|
|
4
|
+
export declare function ensureBoolean(value: boolean | null | undefined): boolean | null | undefined;
|
|
5
|
+
export declare function ensureEnumValue<T extends string>(value: T | null | undefined, enumType: Record<T, string>): T | null | undefined;
|
|
6
|
+
export declare function ensureFilter(filter: boolean | number | null | undefined): boolean | number | null | undefined;
|
|
7
|
+
export declare function ensureNonNegative(value: number | null | undefined): number | null | undefined;
|
|
8
|
+
export declare function ensureValueInRange(value: number | null | undefined, range: [number, number]): number | null | undefined;
|
|
9
|
+
export declare function withFallback<T>(value: T | null | undefined, defaultValue: T | null): T | null;
|
|
@@ -3,10 +3,14 @@ export declare class WebPubBlobBuilder {
|
|
|
3
3
|
private readonly item;
|
|
4
4
|
private readonly burl;
|
|
5
5
|
private readonly pub;
|
|
6
|
-
|
|
6
|
+
private readonly cssProperties?;
|
|
7
|
+
constructor(pub: Publication, baseURL: string, item: Link, cssProperties?: {
|
|
8
|
+
[key: string]: string;
|
|
9
|
+
});
|
|
7
10
|
build(): Promise<string>;
|
|
8
11
|
private buildHtmlFrame;
|
|
9
12
|
private hasExecutable;
|
|
13
|
+
private setProperties;
|
|
10
14
|
private finalizeDOM;
|
|
11
15
|
private serializeAsHTML;
|
|
12
16
|
}
|
|
@@ -5,6 +5,7 @@ export declare class WebPubFrameManager {
|
|
|
5
5
|
private loader;
|
|
6
6
|
readonly source: string;
|
|
7
7
|
private comms;
|
|
8
|
+
private hidden;
|
|
8
9
|
private destroyed;
|
|
9
10
|
private currModules;
|
|
10
11
|
constructor(source: string);
|
|
@@ -12,6 +13,9 @@ export declare class WebPubFrameManager {
|
|
|
12
13
|
destroy(): Promise<void>;
|
|
13
14
|
hide(): Promise<void>;
|
|
14
15
|
show(atProgress?: number): Promise<void>;
|
|
16
|
+
setCSSProperties(properties: {
|
|
17
|
+
[key: string]: string;
|
|
18
|
+
}): void;
|
|
15
19
|
get iframe(): HTMLIFrameElement;
|
|
16
20
|
get realSize(): DOMRect;
|
|
17
21
|
get window(): Window;
|
|
@@ -4,13 +4,20 @@ import { WebPubFrameManager } from "./WebPubFrameManager";
|
|
|
4
4
|
export declare class WebPubFramePoolManager {
|
|
5
5
|
private readonly container;
|
|
6
6
|
private _currentFrame;
|
|
7
|
+
private currentCssProperties;
|
|
7
8
|
private readonly pool;
|
|
8
9
|
private readonly blobs;
|
|
9
10
|
private readonly inprogress;
|
|
11
|
+
private pendingUpdates;
|
|
10
12
|
private currentBaseURL;
|
|
11
|
-
constructor(container: HTMLElement
|
|
13
|
+
constructor(container: HTMLElement, cssProperties?: {
|
|
14
|
+
[key: string]: string;
|
|
15
|
+
});
|
|
12
16
|
destroy(): Promise<void>;
|
|
13
17
|
update(pub: Publication, locator: Locator, modules: ModuleName[]): Promise<void>;
|
|
18
|
+
setCSSProperties(properties: {
|
|
19
|
+
[key: string]: string;
|
|
20
|
+
}): void;
|
|
14
21
|
get currentFrames(): (WebPubFrameManager | undefined)[];
|
|
15
22
|
get currentBounds(): DOMRect;
|
|
16
23
|
}
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import { Link, Locator, Publication, ReadingProgression } from "@readium/shared";
|
|
2
2
|
import { VisualNavigator, VisualNavigatorViewport } from "../Navigator";
|
|
3
|
+
import { Configurable } from "../preferences/Configurable";
|
|
3
4
|
import { BasicTextSelection, CommsEventKey, FrameClickEvent } from "@readium/navigator-html-injectables";
|
|
5
|
+
import { WebPubFrameManager } from "./WebPubFrameManager";
|
|
4
6
|
import { ManagerEventKey } from "../epub/EpubNavigator";
|
|
7
|
+
import { IWebPubPreferences, WebPubPreferences } from "./preferences/WebPubPreferences";
|
|
8
|
+
import { IWebPubDefaults } from "./preferences/WebPubDefaults";
|
|
9
|
+
import { WebPubSettings } from "./preferences/WebPubSettings";
|
|
10
|
+
import { IPreferencesEditor } from "../preferences/PreferencesEditor";
|
|
11
|
+
export interface WebPubNavigatorConfiguration {
|
|
12
|
+
preferences: IWebPubPreferences;
|
|
13
|
+
defaults: IWebPubDefaults;
|
|
14
|
+
}
|
|
5
15
|
export interface WebPubNavigatorListeners {
|
|
6
16
|
frameLoaded: (wnd: Window) => void;
|
|
7
17
|
positionChanged: (locator: Locator) => void;
|
|
@@ -13,16 +23,34 @@ export interface WebPubNavigatorListeners {
|
|
|
13
23
|
handleLocator: (locator: Locator) => boolean;
|
|
14
24
|
textSelected: (selection: BasicTextSelection) => void;
|
|
15
25
|
}
|
|
16
|
-
declare class WebPubNavigator extends VisualNavigator {
|
|
26
|
+
export declare class WebPubNavigator extends VisualNavigator implements Configurable<WebPubSettings, WebPubPreferences> {
|
|
17
27
|
private readonly pub;
|
|
18
28
|
private readonly container;
|
|
19
29
|
private readonly listeners;
|
|
20
30
|
private framePool;
|
|
21
31
|
private currentIndex;
|
|
22
32
|
private currentLocation;
|
|
33
|
+
private _preferences;
|
|
34
|
+
private _defaults;
|
|
35
|
+
private _settings;
|
|
36
|
+
private _css;
|
|
37
|
+
private _preferencesEditor;
|
|
23
38
|
private webViewport;
|
|
24
|
-
constructor(container: HTMLElement, pub: Publication, listeners: WebPubNavigatorListeners, initialPosition?: Locator | undefined);
|
|
39
|
+
constructor(container: HTMLElement, pub: Publication, listeners: WebPubNavigatorListeners, initialPosition?: Locator | undefined, configuration?: WebPubNavigatorConfiguration);
|
|
25
40
|
load(): Promise<void>;
|
|
41
|
+
get settings(): Readonly<WebPubSettings>;
|
|
42
|
+
get preferencesEditor(): IPreferencesEditor;
|
|
43
|
+
submitPreferences(preferences: WebPubPreferences): Promise<void>;
|
|
44
|
+
private applyPreferences;
|
|
45
|
+
private updateCSS;
|
|
46
|
+
private compileCSSProperties;
|
|
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();
|
|
26
54
|
eventListener(key: CommsEventKey | ManagerEventKey, data: unknown): void;
|
|
27
55
|
private determineModules;
|
|
28
56
|
private attachListener;
|
|
@@ -47,4 +75,3 @@ declare class WebPubNavigator extends VisualNavigator {
|
|
|
47
75
|
private createCurrentLocator;
|
|
48
76
|
}
|
|
49
77
|
export declare const ExperimentalWebPubNavigator: typeof WebPubNavigator;
|
|
50
|
-
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { TextAlignment } from "../../preferences/Types";
|
|
2
|
+
import { BodyHyphens, Ligatures, Properties } from "../../css/Properties";
|
|
3
|
+
export interface IWebUserProperties {
|
|
4
|
+
a11yNormalize?: boolean | null;
|
|
5
|
+
bodyHyphens?: BodyHyphens | null;
|
|
6
|
+
fontFamily?: string | null;
|
|
7
|
+
fontWeight?: number | null;
|
|
8
|
+
letterSpacing?: number | null;
|
|
9
|
+
ligatures?: Ligatures | null;
|
|
10
|
+
lineHeight?: number | null;
|
|
11
|
+
noRuby?: boolean | null;
|
|
12
|
+
paraIndent?: number | null;
|
|
13
|
+
paraSpacing?: number | null;
|
|
14
|
+
textAlign?: TextAlignment | null;
|
|
15
|
+
wordSpacing?: number | null;
|
|
16
|
+
zoom: number | null;
|
|
17
|
+
}
|
|
18
|
+
export declare class WebUserProperties extends Properties {
|
|
19
|
+
a11yNormalize: boolean | null;
|
|
20
|
+
bodyHyphens: BodyHyphens | null;
|
|
21
|
+
fontFamily: string | null;
|
|
22
|
+
fontWeight: number | null;
|
|
23
|
+
letterSpacing: number | null;
|
|
24
|
+
ligatures: Ligatures | null;
|
|
25
|
+
lineHeight: number | null;
|
|
26
|
+
noRuby: boolean | null;
|
|
27
|
+
paraIndent: number | null;
|
|
28
|
+
paraSpacing: number | null;
|
|
29
|
+
textAlign: TextAlignment | null;
|
|
30
|
+
wordSpacing: number | null;
|
|
31
|
+
zoom: number | null;
|
|
32
|
+
constructor(props: IWebUserProperties);
|
|
33
|
+
toCSSProperties(): {
|
|
34
|
+
[key: string]: string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WebPubSettings } from "../preferences/WebPubSettings";
|
|
2
|
+
import { WebUserProperties } from "./Properties";
|
|
3
|
+
export interface IWebPubCSS {
|
|
4
|
+
userProperties: WebUserProperties;
|
|
5
|
+
}
|
|
6
|
+
export declare class WebPubCSS {
|
|
7
|
+
userProperties: WebUserProperties;
|
|
8
|
+
constructor(props: IWebPubCSS);
|
|
9
|
+
update(settings: WebPubSettings): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const webPubStylesheet = "\n/* FontFamily */\n\n:root[style*=\"--USER__fontFamily\"] {\n font-family: var(--USER__fontFamily) !important;\n}\n\n:root[style*=\"--USER__fontFamily\"] * {\n font-family: revert !important;\n}\n\n/* FontWeight */\n\n:root[style*=\"--USER__fontWeight\"] body {\n font-weight: var(--USER__fontWeight) !important;\n}\n\n/* Attempt to handle known bolds */\n:root[style*=\"--USER__fontWeight\"] b,\n:root[style*=\"--USER__fontWeight\"] strong {\n font-weight: bolder;\n}\n\n/* Hyphens */\n\n:root[style*=\"--USER__bodyHyphens\"] {\n -webkit-hyphens: var(--USER__bodyHyphens) !important;\n -moz-hyphens: var(--USER__bodyHyphens) !important;\n -ms-hyphens: var(--USER__bodyHyphens) !important;\n -epub-hyphens: var(--USER__bodyHyphens) !important;\n hyphens: var(--USER__bodyHyphens) !important;\n}\n\n:root[style*=\"--USER__bodyHyphens\"] body,\n:root[style*=\"--USER__bodyHyphens\"] p,\n:root[style*=\"--USER__bodyHyphens\"] li,\n:root[style*=\"--USER__bodyHyphens\"] div,\n:root[style*=\"--USER__bodyHyphens\"] dd {\n -webkit-hyphens: inherit;\n -moz-hyphens: inherit;\n -ms-hyphens: inherit;\n -epub-hyphens: inherit;\n hyphens: inherit;\n}\n\n/* LetterSpacing */\n\n:root[style*=\"--USER__letterSpacing\"] h1,\n:root[style*=\"--USER__letterSpacing\"] h2,\n:root[style*=\"--USER__letterSpacing\"] h3,\n:root[style*=\"--USER__letterSpacing\"] h4,\n:root[style*=\"--USER__letterSpacing\"] h5,\n:root[style*=\"--USER__letterSpacing\"] h6,\n:root[style*=\"--USER__letterSpacing\"] p,\n:root[style*=\"--USER__letterSpacing\"] li,\n:root[style*=\"--USER__letterSpacing\"] div,\n:root[style*=\"--USER__letterSpacing\"] dt,\n:root[style*=\"--USER__letterSpacing\"] dd {\n letter-spacing: var(--USER__letterSpacing);\n font-variant: none;\n}\n\n/* Ligatures */\n\n:root[style*=\"--USER__ligatures\"] {\n font-variant-ligatures: var(--USER__ligatures) !important;\n}\n\n:root[style*=\"--USER__ligatures\"] * {\n font-variant-ligatures: inherit !important;\n}\n\n/* LineHeight */\n\n:root[style*=\"--USER__lineHeight\"] {\n line-height: var(--USER__lineHeight) !important;\n}\n\n:root[style*=\"--USER__lineHeight\"] body,\n:root[style*=\"--USER__lineHeight\"] p,\n:root[style*=\"--USER__lineHeight\"] li,\n:root[style*=\"--USER__lineHeight\"] div {\n line-height: inherit;\n}\n\n/* ParagraphIndent */\n\n:root[style*=\"--USER__paraIndent\"] p {\n text-indent: var(--USER__paraIndent) !important;\n}\n\n:root[style*=\"--USER__paraIndent\"] p *,\n:root[style*=\"--USER__paraIndent\"] p:first-letter {\n text-indent: 0 !important;\n}\n\n/* ParagraphSpacing */\n\n:root[style*=\"--USER__paraSpacing\"] p {\n margin-block: var(--USER__paraSpacing) !important;\n}\n\n/* Ruby */\n\n:root[style*=\"readium-noRuby-on\"] body rt,\n:root[style*=\"readium-noRuby-on\"] body rp {\n display: none;\n}\n\n/* TextAlign */\n\n:root[style*=\"--USER__textAlign\"] {\n text-align: var(--USER__textAlign);\n}\n\n:root[style*=\"--USER__textAlign\"] body,\n:root[style*=\"--USER__textAlign\"] p:not(blockquote p):not(figcaption p):not(hgroup p),\n:root[style*=\"--USER__textAlign\"] li,\n:root[style*=\"--USER__textAlign\"] dd {\n text-align: var(--USER__textAlign) !important;\n -moz-text-align-last: auto !important;\n -epub-text-align-last: auto !important;\n text-align-last: auto !important;\n}\n\n/* TextNormalize */\n\n:root[style*=\"readium-a11y-on\"] {\n font-weight: normal !important;\n font-style: normal !important;\n}\n\n:root[style*=\"readium-a11y-on\"] *:not(code):not(var):not(kbd):not(samp) {\n font-family: inherit !important;\n font-weight: inherit !important;\n font-style: inherit !important;\n}\n\n:root[style*=\"readium-a11y-on\"] * {\n text-decoration: none !important;\n font-variant-caps: normal !important;\n font-variant-position: normal !important;\n font-variant-numeric: normal !important;\n}\n\n:root[style*=\"readium-a11y-on\"] sup,\n:root[style*=\"readium-a11y-on\"] sub {\n font-size: 1rem !important;\n vertical-align: baseline !important;\n}\n\n/* Word Spacing */\n\n:root[style*=\"--USER__wordSpacing\"] h1,\n:root[style*=\"--USER__wordSpacing\"] h2,\n:root[style*=\"--USER__wordSpacing\"] h3,\n:root[style*=\"--USER__wordSpacing\"] h4,\n:root[style*=\"--USER__wordSpacing\"] h5,\n:root[style*=\"--USER__wordSpacing\"] h6,\n:root[style*=\"--USER__wordSpacing\"] p,\n:root[style*=\"--USER__wordSpacing\"] li,\n:root[style*=\"--USER__wordSpacing\"] div,\n:root[style*=\"--USER__wordSpacing\"] dt,\n:root[style*=\"--USER__wordSpacing\"] dd {\n word-spacing: var(--USER__wordSpacing);\n}\n\n/* Zoom */\n\n:root {\n --USER__zoom: 1;\n}\n\n:root[style*=\"--USER__zoom\"] body {\n zoom: var(--USER__zoom) !important;\n}\n\n@supports selector(figure:has(> img)) {\n :root[style*=\"--USER__zoom\"] figure:has(> img),\n :root[style*=\"--USER__zoom\"] figure:has(> video),\n :root[style*=\"--USER__zoom\"] figure:has(> svg),\n :root[style*=\"--USER__zoom\"] figure:has(> canvas),\n :root[style*=\"--USER__zoom\"] figure:has(> iframe),\n :root[style*=\"--USER__zoom\"] figure:has(> audio),\n :root[style*=\"--USER__zoom\"] div:has(> img),\n :root[style*=\"--USER__zoom\"] div:has(> video),\n :root[style*=\"--USER__zoom\"] div:has(> svg),\n :root[style*=\"--USER__zoom\"] div:has(> canvas),\n :root[style*=\"--USER__zoom\"] div:has(> iframe),\n :root[style*=\"--USER__zoom\"] div:has(> audio),\n :root[style*=\"--USER__zoom\"] table {\n zoom: calc(100% / var(--USER__zoom)) !important;\n }\n\n :root[style*=\"--USER__zoom\"] figcaption,\n :root[style*=\"--USER__zoom\"] caption,\n :root[style*=\"--USER__zoom\"] td,\n :root[style*=\"--USER__zoom\"] th {\n zoom: var(--USER__zoom) !important;\n }\n}\n";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { TextAlignment } from "../../preferences/Types";
|
|
2
|
+
export interface IWebPubDefaults {
|
|
3
|
+
fontFamily?: string | null;
|
|
4
|
+
fontWeight?: number | null;
|
|
5
|
+
hyphens?: boolean | null;
|
|
6
|
+
letterSpacing?: number | null;
|
|
7
|
+
ligatures?: boolean | null;
|
|
8
|
+
lineHeight?: number | null;
|
|
9
|
+
noRuby?: boolean | null;
|
|
10
|
+
paragraphIndent?: number | null;
|
|
11
|
+
paragraphSpacing?: number | null;
|
|
12
|
+
textAlign?: TextAlignment | null;
|
|
13
|
+
textNormalization?: boolean | null;
|
|
14
|
+
wordSpacing?: number | null;
|
|
15
|
+
zoom?: number | null;
|
|
16
|
+
}
|
|
17
|
+
export declare class WebPubDefaults {
|
|
18
|
+
fontFamily: string | null;
|
|
19
|
+
fontWeight: number | null;
|
|
20
|
+
hyphens: boolean | null;
|
|
21
|
+
letterSpacing: number | null;
|
|
22
|
+
ligatures: boolean | null;
|
|
23
|
+
lineHeight: number | null;
|
|
24
|
+
noRuby: boolean | null;
|
|
25
|
+
paragraphIndent: number | null;
|
|
26
|
+
paragraphSpacing: number | null;
|
|
27
|
+
textAlign: TextAlignment | null;
|
|
28
|
+
textNormalization: boolean | null;
|
|
29
|
+
wordSpacing: number | null;
|
|
30
|
+
zoom: number;
|
|
31
|
+
constructor(defaults: IWebPubDefaults);
|
|
32
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ConfigurablePreferences } from "../../preferences/Configurable";
|
|
2
|
+
import { TextAlignment } from "../../preferences/Types";
|
|
3
|
+
export interface IWebPubPreferences {
|
|
4
|
+
fontFamily?: string | null;
|
|
5
|
+
fontWeight?: number | null;
|
|
6
|
+
hyphens?: boolean | null;
|
|
7
|
+
letterSpacing?: number | null;
|
|
8
|
+
ligatures?: boolean | null;
|
|
9
|
+
lineHeight?: number | null;
|
|
10
|
+
noRuby?: boolean | null;
|
|
11
|
+
paragraphIndent?: number | null;
|
|
12
|
+
paragraphSpacing?: number | null;
|
|
13
|
+
textAlign?: TextAlignment | null;
|
|
14
|
+
textNormalization?: boolean | null;
|
|
15
|
+
wordSpacing?: number | null;
|
|
16
|
+
zoom?: number | null;
|
|
17
|
+
}
|
|
18
|
+
export declare class WebPubPreferences implements ConfigurablePreferences {
|
|
19
|
+
fontFamily?: string | null;
|
|
20
|
+
fontWeight?: number | null;
|
|
21
|
+
hyphens?: boolean | null;
|
|
22
|
+
letterSpacing?: number | null;
|
|
23
|
+
ligatures?: boolean | null;
|
|
24
|
+
lineHeight?: number | null;
|
|
25
|
+
noRuby?: boolean | null;
|
|
26
|
+
paragraphIndent?: number | null;
|
|
27
|
+
paragraphSpacing?: number | null;
|
|
28
|
+
textAlign?: TextAlignment | null;
|
|
29
|
+
textNormalization?: boolean | null;
|
|
30
|
+
wordSpacing?: number | null;
|
|
31
|
+
zoom?: number | null;
|
|
32
|
+
constructor(preferences?: IWebPubPreferences);
|
|
33
|
+
static serialize(preferences: WebPubPreferences): string;
|
|
34
|
+
static deserialize(preferences: string): WebPubPreferences | null;
|
|
35
|
+
merging(other: ConfigurablePreferences): ConfigurablePreferences;
|
|
36
|
+
}
|