@readium/navigator 2.5.0-beta.1 → 2.5.0-beta.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 +949 -928
- package/dist/index.umd.cjs +21 -21
- package/package.json +1 -1
- package/src/epub/EpubNavigator.ts +12 -7
- package/src/epub/css/ReadiumCSS.ts +11 -0
- package/src/epub/helpers/scriptMode.ts +8 -1
- package/src/injection/epubInjectables.ts +5 -1
- package/src/webpub/WebPubNavigator.ts +9 -4
- package/types/src/epub/css/ReadiumCSS.d.ts +2 -0
- package/types/src/epub/helpers/scriptMode.d.ts +4 -1
package/package.json
CHANGED
|
@@ -115,9 +115,11 @@ export class EpubNavigator extends VisualNavigator implements Configurable<Confi
|
|
|
115
115
|
const scriptMode = getScriptMode(pub.metadata);
|
|
116
116
|
const isCJKHorizontal = scriptMode === 'cjk-horizontal';
|
|
117
117
|
const isCJKVertical = scriptMode === 'cjk-vertical';
|
|
118
|
+
const isMongolianVertical = scriptMode === 'mongolian-vertical';
|
|
119
|
+
const isVertical = isCJKVertical || isMongolianVertical;
|
|
118
120
|
const isCJK = isCJKHorizontal || isCJKVertical;
|
|
119
121
|
this._css = new ReadiumCSS({
|
|
120
|
-
rsProperties: new RSProperties({ noVerticalPagination:
|
|
122
|
+
rsProperties: new RSProperties({ noVerticalPagination: isVertical || undefined }),
|
|
121
123
|
userProperties: new UserProperties({}),
|
|
122
124
|
lineLengths: new LineLengths({
|
|
123
125
|
optimalChars: this._settings.optimalLineLength,
|
|
@@ -133,7 +135,8 @@ export class EpubNavigator extends VisualNavigator implements Configurable<Confi
|
|
|
133
135
|
// sample: this.pub.metadata.description
|
|
134
136
|
}),
|
|
135
137
|
container: container,
|
|
136
|
-
constraint: this._settings.constraint
|
|
138
|
+
constraint: this._settings.constraint,
|
|
139
|
+
isCJKVertical: isVertical
|
|
137
140
|
});
|
|
138
141
|
|
|
139
142
|
this._layout = EpubNavigator.determineLayout(pub, !!this._settings.scroll);
|
|
@@ -209,9 +212,10 @@ export class EpubNavigator extends VisualNavigator implements Configurable<Confi
|
|
|
209
212
|
if (layout === Layout.scrolled)
|
|
210
213
|
return Layout.scrolled;
|
|
211
214
|
|
|
212
|
-
// CJK vertical writing: force scroll mode so the
|
|
213
|
-
// used and column-based pagination doesn't interfere.
|
|
214
|
-
|
|
215
|
+
// CJK/Mongolian vertical writing: force scroll mode so the
|
|
216
|
+
// CJKVerticalSnapper is used and column-based pagination doesn't interfere.
|
|
217
|
+
const sm = getScriptMode(pub.metadata);
|
|
218
|
+
if (sm === 'cjk-vertical' || sm === 'mongolian-vertical')
|
|
215
219
|
return Layout.scrolled;
|
|
216
220
|
|
|
217
221
|
if (layout === Layout.reflowable && scroll)
|
|
@@ -554,8 +558,9 @@ export class EpubNavigator extends VisualNavigator implements Configurable<Confi
|
|
|
554
558
|
return modules.filter((m) => FXLModules.includes(m));
|
|
555
559
|
} else modules = modules.filter((m) => ReflowableModules.includes(m));
|
|
556
560
|
|
|
557
|
-
// CJK vertical: uses
|
|
558
|
-
|
|
561
|
+
// CJK/Mongolian vertical: uses the X-axis snapper, never column or scroll snappers
|
|
562
|
+
const mode = getScriptMode(this.pub.metadata);
|
|
563
|
+
if (mode === 'cjk-vertical' || mode === 'mongolian-vertical') {
|
|
559
564
|
return modules.filter((m) => m !== "column_snapper" && m !== "scroll_snapper");
|
|
560
565
|
}
|
|
561
566
|
|
|
@@ -9,6 +9,7 @@ export interface IReadiumCSS {
|
|
|
9
9
|
lineLengths: LineLengths;
|
|
10
10
|
container: HTMLElement;
|
|
11
11
|
constraint: number;
|
|
12
|
+
isCJKVertical?: boolean;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export class ReadiumCSS {
|
|
@@ -18,6 +19,7 @@ export class ReadiumCSS {
|
|
|
18
19
|
container: HTMLElement;
|
|
19
20
|
containerParent: HTMLElement;
|
|
20
21
|
constraint: number;
|
|
22
|
+
private readonly isCJKVertical: boolean;
|
|
21
23
|
private cachedColCount: number | null | undefined;
|
|
22
24
|
private effectiveContainerWidth: number;
|
|
23
25
|
|
|
@@ -28,6 +30,7 @@ export class ReadiumCSS {
|
|
|
28
30
|
this.container = props.container;
|
|
29
31
|
this.containerParent = props.container.parentElement || document.documentElement;
|
|
30
32
|
this.constraint = props.constraint;
|
|
33
|
+
this.isCJKVertical = props.isCJKVertical ?? false;
|
|
31
34
|
this.cachedColCount = props.userProperties.colCount;
|
|
32
35
|
this.effectiveContainerWidth = getContentWidth(this.containerParent);
|
|
33
36
|
}
|
|
@@ -131,6 +134,14 @@ export class ReadiumCSS {
|
|
|
131
134
|
}
|
|
132
135
|
|
|
133
136
|
private updateLayout(scale: number | null, ignoreCompensation: boolean | null, scroll: boolean | null, colCount?: number | null) {
|
|
137
|
+
// CJK vertical text flows along the block axis (height); the inline axis
|
|
138
|
+
// (width) must not be constrained by line-length at all — use the full
|
|
139
|
+
// parent width minus the known constraint.
|
|
140
|
+
if (this.isCJKVertical) {
|
|
141
|
+
const w = Math.round(getContentWidth(this.containerParent) - this.constraint);
|
|
142
|
+
return { colCount: undefined, effectiveContainerWidth: w, effectiveLineLength: w };
|
|
143
|
+
}
|
|
144
|
+
|
|
134
145
|
const isScroll = scroll ?? this.userProperties.view === "scroll";
|
|
135
146
|
|
|
136
147
|
if (isScroll) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Metadata, ReadingProgression } from "@readium/shared";
|
|
2
2
|
|
|
3
|
-
export type ScriptMode = 'ltr' | 'rtl' | 'cjk-horizontal' | 'cjk-vertical';
|
|
3
|
+
export type ScriptMode = 'ltr' | 'rtl' | 'cjk-horizontal' | 'cjk-vertical' | 'mongolian-vertical';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Derives the script mode from publication metadata.
|
|
@@ -14,6 +14,9 @@ export type ScriptMode = 'ltr' | 'rtl' | 'cjk-horizontal' | 'cjk-vertical';
|
|
|
14
14
|
* - For RTL (ar/fa/he): language wins. If the primary language is a RTL
|
|
15
15
|
* script, RTL mode is applied regardless of the explicit progression
|
|
16
16
|
* direction declared in the OPF.
|
|
17
|
+
* - For Mongolian (mn): Traditional Mongolian script (mn-Mong) uses
|
|
18
|
+
* writing-mode: vertical-lr. Cyrillic Mongolian (mn-Cyrl) is standard LTR.
|
|
19
|
+
* An explicit script subtag is required; bare `mn` defaults to LTR.
|
|
17
20
|
*/
|
|
18
21
|
export function getScriptMode(metadata: Metadata): ScriptMode {
|
|
19
22
|
const primaryLang = metadata.languages?.[0]?.toLowerCase();
|
|
@@ -33,6 +36,10 @@ export function getScriptMode(metadata: Metadata): ScriptMode {
|
|
|
33
36
|
: 'cjk-horizontal';
|
|
34
37
|
}
|
|
35
38
|
|
|
39
|
+
// Traditional Mongolian script (mn-Mong): writing-mode vertical-lr.
|
|
40
|
+
// Requires an explicit Mong script subtag; mn-Cyrl and bare mn stay LTR.
|
|
41
|
+
if (primaryLang.startsWith('mn-mong')) return 'mongolian-vertical';
|
|
42
|
+
|
|
36
43
|
// RTL: language is authoritative. ar/fa/he → rtl regardless of
|
|
37
44
|
// what the OPF says about page-progression-direction.
|
|
38
45
|
const isRTLScript = primaryLang.startsWith('ar') ||
|
|
@@ -86,7 +86,11 @@ export async function createReadiumEpubRules(metadata: Metadata, readingOrderIte
|
|
|
86
86
|
cssAfterRaw = after.default;
|
|
87
87
|
break;
|
|
88
88
|
}
|
|
89
|
-
case 'cjk-vertical':
|
|
89
|
+
case 'cjk-vertical':
|
|
90
|
+
// Traditional Mongolian (vertical-lr) uses the same Readium CSS
|
|
91
|
+
// layout as CJK vertical-rl — it is an outlier handled by the
|
|
92
|
+
// same stylesheet set per the Readium CSS spec.
|
|
93
|
+
case 'mongolian-vertical': {
|
|
90
94
|
const [before, def, after] = await Promise.all([
|
|
91
95
|
import("@readium/css/css/dist/cjk-vertical/ReadiumCSS-before.css?raw"),
|
|
92
96
|
import("@readium/css/css/dist/cjk-vertical/ReadiumCSS-default.css?raw"),
|
|
@@ -2,11 +2,12 @@ import { Feature, Link, Locator, Publication, ReadingProgression, LocatorLocatio
|
|
|
2
2
|
import { VisualNavigator, VisualNavigatorViewport, ProgressionRange } from "../Navigator.ts";
|
|
3
3
|
import { Configurable } from "../preferences/Configurable.ts";
|
|
4
4
|
import { WebPubFramePoolManager } from "./WebPubFramePoolManager.ts";
|
|
5
|
-
import { BasicTextSelection, CommsEventKey, ContextMenuEvent, FrameClickEvent, KeyboardEventData,
|
|
5
|
+
import { BasicTextSelection, CommsEventKey, ContextMenuEvent, FrameClickEvent, KeyboardEventData, ModuleName, SuspiciousActivityEvent, WebPubModules } from "@readium/navigator-html-injectables";
|
|
6
6
|
import * as path from "path-browserify";
|
|
7
7
|
import { WebPubFrameManager } from "./WebPubFrameManager.ts";
|
|
8
8
|
|
|
9
9
|
import { ManagerEventKey } from "../epub/EpubNavigator.ts";
|
|
10
|
+
import { getScriptMode } from "../epub/helpers/scriptMode.ts";
|
|
10
11
|
import { WebPubCSS } from "./css/WebPubCSS.ts";
|
|
11
12
|
import { WebUserProperties, WebRSProperties } from "./css/Properties.ts";
|
|
12
13
|
import { IWebPubPreferences, WebPubPreferences } from "./preferences/WebPubPreferences.ts";
|
|
@@ -367,10 +368,14 @@ export class WebPubNavigator extends VisualNavigator implements Configurable<Web
|
|
|
367
368
|
}
|
|
368
369
|
|
|
369
370
|
private determineModules(): ModuleName[] {
|
|
370
|
-
|
|
371
|
+
const modules = WebPubModules.slice();
|
|
371
372
|
|
|
372
|
-
|
|
373
|
-
|
|
373
|
+
const mode = getScriptMode(this.pub.metadata);
|
|
374
|
+
if (mode === 'cjk-vertical' || mode === 'mongolian-vertical') {
|
|
375
|
+
return modules.map((m) => m === "webpub_snapper" ? "cjk_vertical_snapper" : m);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return modules;
|
|
374
379
|
}
|
|
375
380
|
|
|
376
381
|
private attachListener() {
|
|
@@ -7,6 +7,7 @@ export interface IReadiumCSS {
|
|
|
7
7
|
lineLengths: LineLengths;
|
|
8
8
|
container: HTMLElement;
|
|
9
9
|
constraint: number;
|
|
10
|
+
isCJKVertical?: boolean;
|
|
10
11
|
}
|
|
11
12
|
export declare class ReadiumCSS {
|
|
12
13
|
rsProperties: RSProperties;
|
|
@@ -15,6 +16,7 @@ export declare class ReadiumCSS {
|
|
|
15
16
|
container: HTMLElement;
|
|
16
17
|
containerParent: HTMLElement;
|
|
17
18
|
constraint: number;
|
|
19
|
+
private readonly isCJKVertical;
|
|
18
20
|
private cachedColCount;
|
|
19
21
|
private effectiveContainerWidth;
|
|
20
22
|
constructor(props: IReadiumCSS);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Metadata } from "@readium/shared";
|
|
2
|
-
export type ScriptMode = 'ltr' | 'rtl' | 'cjk-horizontal' | 'cjk-vertical';
|
|
2
|
+
export type ScriptMode = 'ltr' | 'rtl' | 'cjk-horizontal' | 'cjk-vertical' | 'mongolian-vertical';
|
|
3
3
|
/**
|
|
4
4
|
* Derives the script mode from publication metadata.
|
|
5
5
|
*
|
|
@@ -12,5 +12,8 @@ export type ScriptMode = 'ltr' | 'rtl' | 'cjk-horizontal' | 'cjk-vertical';
|
|
|
12
12
|
* - For RTL (ar/fa/he): language wins. If the primary language is a RTL
|
|
13
13
|
* script, RTL mode is applied regardless of the explicit progression
|
|
14
14
|
* direction declared in the OPF.
|
|
15
|
+
* - For Mongolian (mn): Traditional Mongolian script (mn-Mong) uses
|
|
16
|
+
* writing-mode: vertical-lr. Cyrillic Mongolian (mn-Cyrl) is standard LTR.
|
|
17
|
+
* An explicit script subtag is required; bare `mn` defaults to LTR.
|
|
15
18
|
*/
|
|
16
19
|
export declare function getScriptMode(metadata: Metadata): ScriptMode;
|