@readium/navigator 2.2.0 → 2.2.1

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.
Files changed (48) hide show
  1. package/dist/index.js +1886 -1321
  2. package/dist/index.umd.cjs +218 -17
  3. package/package.json +1 -1
  4. package/src/css/Properties.ts +47 -0
  5. package/src/css/index.ts +1 -0
  6. package/src/epub/css/Properties.ts +10 -48
  7. package/src/epub/preferences/EpubDefaults.ts +1 -1
  8. package/src/epub/preferences/EpubPreferences.ts +1 -1
  9. package/src/epub/preferences/EpubPreferencesEditor.ts +30 -23
  10. package/src/index.ts +2 -1
  11. package/src/preferences/Types.ts +40 -0
  12. package/src/{epub/preferences → preferences}/guards.ts +5 -6
  13. package/src/preferences/index.ts +2 -1
  14. package/src/webpub/WebPubBlobBuilder.ts +26 -4
  15. package/src/webpub/WebPubFrameManager.ts +16 -0
  16. package/src/webpub/WebPubFramePoolManager.ts +49 -2
  17. package/src/webpub/WebPubNavigator.ts +87 -10
  18. package/src/webpub/css/Properties.ts +71 -0
  19. package/src/webpub/css/WebPubCSS.ts +42 -0
  20. package/src/webpub/css/WebPubStylesheet.ts +204 -0
  21. package/src/webpub/css/index.ts +3 -0
  22. package/src/webpub/index.ts +3 -1
  23. package/src/webpub/preferences/WebPubDefaults.ts +61 -0
  24. package/src/webpub/preferences/WebPubPreferences.ts +88 -0
  25. package/src/webpub/preferences/WebPubPreferencesEditor.ts +193 -0
  26. package/src/webpub/preferences/WebPubSettings.ts +88 -0
  27. package/src/webpub/preferences/index.ts +4 -0
  28. package/types/src/css/Properties.d.ts +20 -0
  29. package/types/src/css/index.d.ts +1 -0
  30. package/types/src/epub/css/Properties.d.ts +1 -21
  31. package/types/src/index.d.ts +1 -0
  32. package/types/src/preferences/Types.d.ts +8 -0
  33. package/types/src/preferences/guards.d.ts +9 -0
  34. package/types/src/preferences/index.d.ts +1 -0
  35. package/types/src/webpub/WebPubBlobBuilder.d.ts +5 -1
  36. package/types/src/webpub/WebPubFrameManager.d.ts +4 -0
  37. package/types/src/webpub/WebPubFramePoolManager.d.ts +8 -1
  38. package/types/src/webpub/WebPubNavigator.d.ts +23 -3
  39. package/types/src/webpub/css/Properties.d.ts +36 -0
  40. package/types/src/webpub/css/WebPubCSS.d.ts +10 -0
  41. package/types/src/webpub/css/WebPubStylesheet.d.ts +1 -0
  42. package/types/src/webpub/css/index.d.ts +3 -0
  43. package/types/src/webpub/index.d.ts +2 -0
  44. package/types/src/webpub/preferences/WebPubDefaults.d.ts +32 -0
  45. package/types/src/webpub/preferences/WebPubPreferences.d.ts +36 -0
  46. package/types/src/webpub/preferences/WebPubPreferencesEditor.d.ts +27 -0
  47. package/types/src/webpub/preferences/WebPubSettings.d.ts +35 -0
  48. package/types/src/webpub/preferences/index.d.ts +4 -0
@@ -0,0 +1,193 @@
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
+ get fontFamily(): Preference<string> {
37
+ return new Preference<string>({
38
+ initialValue: this.preferences.fontFamily,
39
+ effectiveValue: this.settings.fontFamily || null,
40
+ isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
41
+ onChange: (newValue: string | null | undefined) => {
42
+ this.updatePreference("fontFamily", newValue || null);
43
+ }
44
+ });
45
+ }
46
+
47
+ get fontWeight(): RangePreference<number> {
48
+ return new RangePreference<number>({
49
+ initialValue: this.preferences.fontWeight,
50
+ effectiveValue: this.settings.fontWeight || 400,
51
+ isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
52
+ onChange: (newValue: number | null | undefined) => {
53
+ this.updatePreference("fontWeight", newValue || null);
54
+ },
55
+ supportedRange: fontWeightRangeConfig.range,
56
+ step: fontWeightRangeConfig.step
57
+ });
58
+ }
59
+
60
+ get hyphens(): BooleanPreference {
61
+ return new BooleanPreference({
62
+ initialValue: this.preferences.hyphens,
63
+ effectiveValue: this.settings.hyphens || false,
64
+ isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
65
+ onChange: (newValue: boolean | null | undefined) => {
66
+ this.updatePreference("hyphens", newValue || null);
67
+ }
68
+ });
69
+ }
70
+
71
+ get letterSpacing(): RangePreference<number> {
72
+ return new RangePreference<number>({
73
+ initialValue: this.preferences.letterSpacing,
74
+ effectiveValue: this.settings.letterSpacing || 0,
75
+ isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
76
+ onChange: (newValue: number | null | undefined) => {
77
+ this.updatePreference("letterSpacing", newValue || null);
78
+ },
79
+ supportedRange: letterSpacingRangeConfig.range,
80
+ step: letterSpacingRangeConfig.step
81
+ });
82
+ }
83
+
84
+ get ligatures(): BooleanPreference {
85
+ return new BooleanPreference({
86
+ initialValue: this.preferences.ligatures,
87
+ effectiveValue: this.settings.ligatures || true,
88
+ isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
89
+ onChange: (newValue: boolean | null | undefined) => {
90
+ this.updatePreference("ligatures", newValue || null);
91
+ }
92
+ });
93
+ }
94
+
95
+ get lineHeight(): RangePreference<number> {
96
+ return new RangePreference<number>({
97
+ initialValue: this.preferences.lineHeight,
98
+ effectiveValue: this.settings.lineHeight,
99
+ isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
100
+ onChange: (newValue: number | null | undefined) => {
101
+ this.updatePreference("lineHeight", newValue || null);
102
+ },
103
+ supportedRange: lineHeightRangeConfig.range,
104
+ step: lineHeightRangeConfig.step
105
+ });
106
+ }
107
+
108
+ get noRuby(): BooleanPreference {
109
+ return new BooleanPreference({
110
+ initialValue: this.preferences.noRuby,
111
+ effectiveValue: this.settings.noRuby || false,
112
+ isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
113
+ onChange: (newValue: boolean | null | undefined) => {
114
+ this.updatePreference("noRuby", newValue || null);
115
+ }
116
+ });
117
+ }
118
+
119
+ get paragraphIndent(): RangePreference<number> {
120
+ return new RangePreference<number>({
121
+ initialValue: this.preferences.paragraphIndent,
122
+ effectiveValue: this.settings.paragraphIndent || 0,
123
+ isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
124
+ onChange: (newValue: number | null | undefined) => {
125
+ this.updatePreference("paragraphIndent", newValue || null);
126
+ },
127
+ supportedRange: paragraphIndentRangeConfig.range,
128
+ step: paragraphIndentRangeConfig.step
129
+ });
130
+ }
131
+
132
+ get paragraphSpacing(): RangePreference<number> {
133
+ return new RangePreference<number>({
134
+ initialValue: this.preferences.paragraphSpacing,
135
+ effectiveValue: this.settings.paragraphSpacing || 0,
136
+ isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
137
+ onChange: (newValue: number | null | undefined) => {
138
+ this.updatePreference("paragraphSpacing", newValue || null);
139
+ },
140
+ supportedRange: paragraphSpacingRangeConfig.range,
141
+ step: paragraphSpacingRangeConfig.step
142
+ });
143
+ }
144
+
145
+ get textAlign(): EnumPreference<TextAlignment> {
146
+ return new EnumPreference<TextAlignment>({
147
+ initialValue: this.preferences.textAlign,
148
+ effectiveValue: this.settings.textAlign || TextAlignment.start,
149
+ isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
150
+ onChange: (newValue: TextAlignment | null | undefined) => {
151
+ this.updatePreference("textAlign", newValue || null);
152
+ },
153
+ supportedValues: Object.values(TextAlignment)
154
+ });
155
+ }
156
+
157
+ get textNormalization(): BooleanPreference {
158
+ return new BooleanPreference({
159
+ initialValue: this.preferences.textNormalization,
160
+ effectiveValue: this.settings.textNormalization || false,
161
+ isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
162
+ onChange: (newValue: boolean | null | undefined) => {
163
+ this.updatePreference("textNormalization", newValue || null);
164
+ }
165
+ });
166
+ }
167
+
168
+ get wordSpacing(): RangePreference<number> {
169
+ return new RangePreference<number>({
170
+ initialValue: this.preferences.wordSpacing,
171
+ effectiveValue: this.settings.wordSpacing || 0,
172
+ isEffective: this.metadata?.accessibility?.feature?.includes(Feature.DISPLAY_TRANSFORMABILITY) ?? false,
173
+ onChange: (newValue: number | null | undefined) => {
174
+ this.updatePreference("wordSpacing", newValue || null);
175
+ },
176
+ supportedRange: wordSpacingRangeConfig.range,
177
+ step: wordSpacingRangeConfig.step
178
+ });
179
+ }
180
+
181
+ get zoom(): RangePreference<number> {
182
+ return new RangePreference<number>({
183
+ initialValue: this.preferences.zoom,
184
+ effectiveValue: this.settings.zoom || 1,
185
+ isEffective: CSS.supports("zoom", "1") ?? false,
186
+ onChange: (newValue: number | null | undefined) => {
187
+ this.updatePreference("zoom", newValue || null);
188
+ },
189
+ supportedRange: zoomRangeConfig.range,
190
+ step: zoomRangeConfig.step
191
+ });
192
+ }
193
+ }
@@ -0,0 +1,88 @@
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;
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;
35
+ zoom: number | null;
36
+
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;
82
+ this.zoom = preferences.zoom !== undefined
83
+ ? preferences.zoom
84
+ : defaults.zoom !== undefined
85
+ ? defaults.zoom
86
+ : null;
87
+ }
88
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./WebPubDefaults";
2
+ export * from "./WebPubPreferencesEditor";
3
+ export * from "./WebPubPreferences";
4
+ export * from "./WebPubSettings";
@@ -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
- export type BodyHyphens = "auto" | "none";
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 {};
@@ -4,3 +4,4 @@ export * from './epub';
4
4
  export * from './audio';
5
5
  export * from './helpers';
6
6
  export * from './preferences';
7
+ export * from './css';
@@ -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;
@@ -2,3 +2,4 @@ export * from "./Configurable";
2
2
  export * from "./Preference";
3
3
  export * from "./PreferencesEditor";
4
4
  export * from "./Types";
5
+ export * from "./guards";
@@ -3,10 +3,14 @@ export declare class WebPubBlobBuilder {
3
3
  private readonly item;
4
4
  private readonly burl;
5
5
  private readonly pub;
6
- constructor(pub: Publication, baseURL: string, item: Link);
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,16 @@
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";
4
5
  import { ManagerEventKey } from "../epub/EpubNavigator";
6
+ import { IWebPubPreferences, WebPubPreferences } from "./preferences/WebPubPreferences";
7
+ import { IWebPubDefaults } from "./preferences/WebPubDefaults";
8
+ import { WebPubSettings } from "./preferences/WebPubSettings";
9
+ import { IPreferencesEditor } from "../preferences/PreferencesEditor";
10
+ export interface WebPubNavigatorConfiguration {
11
+ preferences: IWebPubPreferences;
12
+ defaults: IWebPubDefaults;
13
+ }
5
14
  export interface WebPubNavigatorListeners {
6
15
  frameLoaded: (wnd: Window) => void;
7
16
  positionChanged: (locator: Locator) => void;
@@ -13,16 +22,28 @@ export interface WebPubNavigatorListeners {
13
22
  handleLocator: (locator: Locator) => boolean;
14
23
  textSelected: (selection: BasicTextSelection) => void;
15
24
  }
16
- declare class WebPubNavigator extends VisualNavigator {
25
+ export declare class WebPubNavigator extends VisualNavigator implements Configurable<WebPubSettings, WebPubPreferences> {
17
26
  private readonly pub;
18
27
  private readonly container;
19
28
  private readonly listeners;
20
29
  private framePool;
21
30
  private currentIndex;
22
31
  private currentLocation;
32
+ private _preferences;
33
+ private _defaults;
34
+ private _settings;
35
+ private _css;
36
+ private _preferencesEditor;
23
37
  private webViewport;
24
- constructor(container: HTMLElement, pub: Publication, listeners: WebPubNavigatorListeners, initialPosition?: Locator | undefined);
38
+ constructor(container: HTMLElement, pub: Publication, listeners: WebPubNavigatorListeners, initialPosition?: Locator | undefined, configuration?: WebPubNavigatorConfiguration);
25
39
  load(): Promise<void>;
40
+ get settings(): Readonly<WebPubSettings>;
41
+ get preferencesEditor(): IPreferencesEditor;
42
+ submitPreferences(preferences: WebPubPreferences): Promise<void>;
43
+ private applyPreferences;
44
+ private updateCSS;
45
+ private compileCSSProperties;
46
+ private commitCSS;
26
47
  eventListener(key: CommsEventKey | ManagerEventKey, data: unknown): void;
27
48
  private determineModules;
28
49
  private attachListener;
@@ -47,4 +68,3 @@ declare class WebPubNavigator extends VisualNavigator {
47
68
  private createCurrentLocator;
48
69
  }
49
70
  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,3 @@
1
+ export * from "./Properties";
2
+ export * from "./WebPubCSS";
3
+ export * from "./WebPubStylesheet";
@@ -2,3 +2,5 @@ export * from "./WebPubNavigator";
2
2
  export * from "./WebPubBlobBuilder";
3
3
  export * from "./WebPubFrameManager";
4
4
  export * from "./WebPubFramePoolManager";
5
+ export * from "./preferences";
6
+ export * from "./css";
@@ -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
+ }