Skip to content

Commit f71acd4

Browse files
authored
Readium css beta.22 (#168)
1 parent e34b47d commit f71acd4

File tree

13 files changed

+128
-225
lines changed

13 files changed

+128
-225
lines changed

navigator/CHANGELOG.MD

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ 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.4] - 2025-11-06
9+
10+
### Added
11+
12+
- Added the handling of iOS and iPadOS patches to the WebPub Preferences API
13+
14+
### Changed
15+
16+
- Updated ReadiumCSS to `v2.0.0-beta.22`
17+
- Switched experimental WebPublication Navigator Preferences to ReadiumCSS
18+
- Updated ligatures handling in EpubPreferencesEditor to match ReadiumCSS
19+
820
## [2.2.3] - 2025-11-01
921

1022
### Fixed

navigator/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@readium/navigator",
3-
"version": "2.2.3",
3+
"version": "2.2.4",
44
"type": "module",
55
"description": "Next generation SDK for publications in Web Apps",
66
"author": "readium",
@@ -49,7 +49,7 @@
4949
},
5050
"devDependencies": {
5151
"@laynezh/vite-plugin-lib-assets": "^2.1.0",
52-
"@readium/css": "2.0.0-beta.20",
52+
"@readium/css": "2.0.0-beta.22",
5353
"@readium/navigator-html-injectables": "workspace:*",
5454
"@readium/shared": "workspace:*",
5555
"@types/path-browserify": "^1.0.3",

navigator/src/epub/preferences/EpubPreferencesEditor.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,30 @@ export class EpubPreferencesEditor implements IPreferencesEditor {
256256
return new BooleanPreference({
257257
initialValue: this.preferences.ligatures,
258258
effectiveValue: this.settings.ligatures || true,
259-
isEffective: this.layout !== Layout.fixed
260-
&& this.metadata?.languages?.some(lang => lang === "ar" || lang === "fa")
261-
&& this.preferences.ligatures !== null || false,
259+
isEffective: (() => {
260+
// Always respect explicit null (disabled) preference
261+
if (this.preferences.ligatures === null) {
262+
return false;
263+
}
264+
265+
// Disable for fixed layout
266+
if (this.layout === Layout.fixed) {
267+
return false;
268+
}
269+
270+
// Check for languages/scripts that should disable ligatures
271+
// ReadiumCSS does not apply in CJK
272+
const primaryLang = this.metadata?.languages?.[0]?.toLowerCase();
273+
if (primaryLang) {
274+
// Disable for Chinese, Japanese, Korean, and Traditional Mongolian (mn-Mong)
275+
if (["zh", "ja", "ko", "mn-mong"].some(lang => primaryLang.startsWith(lang))) {
276+
return false;
277+
}
278+
}
279+
280+
// Enable by default
281+
return true;
282+
})(),
262283
onChange: (newValue: boolean | null | undefined) => {
263284
this.updatePreference("ligatures", newValue || null);
264285
}

navigator/src/webpub/WebPubBlobBuilder.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
11
import { Link, Publication } from "@readium/shared";
2-
import { webPubStylesheet } from "./css/WebPubStylesheet";
32

4-
// Utilities (matching FrameBlobBuilder pattern)
3+
// Readium CSS imports
4+
// The "?inline" query is to prevent some bundlers from injecting these into the page (e.g. vite)
5+
// @ts-ignore
6+
import readiumCSSWebPub from "@readium/css/css/dist/webPub/ReadiumCSS-webPub.css?inline";
7+
8+
// Utilities
59
const blobify = (source: string, type: string) => URL.createObjectURL(new Blob([source], { type }));
610
const stripJS = (source: string) => source.replace(/\/\/.*/g, "").replace(/\/\*[\s\S]*?\*\//g, "").replace(/\n/g, "").replace(/\s+/g, " ");
11+
const stripCSS = (source: string) => source.replace(/\/\*(?:(?!\*\/)[\s\S])*\*\/|[\r\n\t]+/g, '').replace(/ {2,}/g, ' ')
12+
// Fully resolve absolute local URLs created by bundlers since it's going into a blob
13+
.replace(/url\((?!(https?:)?\/\/)("?)\/([^\)]+)/g, `url($2${window.location.origin}/$3`);
714
const scriptify = (doc: Document, source: string) => {
815
const s = doc.createElement("script");
916
s.dataset.readium = "true";
1017
s.src = source.startsWith("blob:") ? source : blobify(source, "text/javascript");
1118
return s;
1219
}
1320
const styleify = (doc: Document, source: string) => {
14-
const s = doc.createElement("style");
21+
const s = doc.createElement("link");
1522
s.dataset.readium = "true";
16-
s.textContent = source;
23+
s.rel = "stylesheet";
24+
s.type = "text/css";
25+
s.href = source.startsWith("blob:") ? source : blobify(source, "text/css");
1726
return s;
1827
}
1928

2029
type CacheFunction = () => string;
2130
const resourceBlobCache = new Map<string, string>();
2231
const cached = (key: string, cacher: CacheFunction) => {
23-
if (resourceBlobCache.has(key)) return resourceBlobCache.get(key)!;
32+
if(resourceBlobCache.has(key)) return resourceBlobCache.get(key)!;
2433
const value = cacher();
2534
resourceBlobCache.set(key, value);
2635
return value;
@@ -103,9 +112,9 @@ export class WebPubBlobBuilder {
103112
private finalizeDOM(doc: Document, base: string | undefined, mediaType: any, txt?: string, cssProperties?: { [key: string]: string }): string {
104113
if(!doc) return "";
105114

106-
// Add WebPubCSS stylesheet at end of head (like EPUB ReadiumCSS-after)
107-
const webPubStyle = styleify(doc, webPubStylesheet);
108-
doc.head.appendChild(webPubStyle);
115+
// ReadiumCSS WebPub
116+
doc.head.appendChild(styleify(doc, cached("ReadiumCSS-webpub", () => blobify(stripCSS(readiumCSSWebPub), "text/css"))));
117+
109118
if (cssProperties) {
110119
this.setProperties(cssProperties, doc);
111120
}

navigator/src/webpub/css/Properties.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export interface IWebUserProperties {
66
bodyHyphens?: BodyHyphens | null;
77
fontFamily?: string | null;
88
fontWeight?: number | null;
9+
iOSPatch?: boolean | null;
10+
iPadOSPatch?: boolean | null;
911
letterSpacing?: number | null;
1012
ligatures?: Ligatures | null;
1113
lineHeight?: number | null;
@@ -22,6 +24,8 @@ export class WebUserProperties extends Properties {
2224
bodyHyphens: BodyHyphens | null;
2325
fontFamily: string | null;
2426
fontWeight: number | null;
27+
iOSPatch: boolean | null;
28+
iPadOSPatch: boolean | null;
2529
letterSpacing: number | null;
2630
ligatures: Ligatures | null;
2731
lineHeight: number | null;
@@ -38,6 +42,8 @@ export class WebUserProperties extends Properties {
3842
this.bodyHyphens = props.bodyHyphens ?? null;
3943
this.fontFamily = props.fontFamily ?? null;
4044
this.fontWeight = props.fontWeight ?? null;
45+
this.iOSPatch = props.iOSPatch ?? null;
46+
this.iPadOSPatch = props.iPadOSPatch ?? null;
4147
this.letterSpacing = props.letterSpacing ?? null;
4248
this.ligatures = props.ligatures ?? null;
4349
this.lineHeight = props.lineHeight ?? null;
@@ -56,6 +62,8 @@ export class WebUserProperties extends Properties {
5662
if (this.bodyHyphens) cssProperties["--USER__bodyHyphens"] = this.bodyHyphens;
5763
if (this.fontFamily) cssProperties["--USER__fontFamily"] = this.fontFamily;
5864
if (this.fontWeight != null) cssProperties["--USER__fontWeight"] = this.toUnitless(this.fontWeight);
65+
if (this.iOSPatch) cssProperties["--USER__iOSPatch"] = this.toFlag("iOSPatch");
66+
if (this.iPadOSPatch) cssProperties["--USER__iPadOSPatch"] = this.toFlag("iPadOSPatch");
5967
if (this.letterSpacing != null) cssProperties["--USER__letterSpacing"] = this.toRem(this.letterSpacing);
6068
if (this.ligatures) cssProperties["--USER__ligatures"] = this.ligatures;
6169
if (this.lineHeight != null) cssProperties["--USER__lineHeight"] = this.toUnitless(this.lineHeight);

navigator/src/webpub/css/WebPubCSS.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export class WebPubCSS {
2222
: "none",
2323
fontFamily: settings.fontFamily,
2424
fontWeight: settings.fontWeight,
25+
iOSPatch: settings.iOSPatch,
26+
iPadOSPatch: settings.iPadOSPatch,
2527
letterSpacing: settings.letterSpacing,
2628
ligatures: typeof settings.ligatures !== "boolean"
2729
? null

navigator/src/webpub/css/WebPubStylesheet.ts

Lines changed: 0 additions & 205 deletions
This file was deleted.

navigator/src/webpub/css/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export * from "./Properties";
2-
export * from "./WebPubCSS";
3-
export * from "./WebPubStylesheet";
2+
export * from "./WebPubCSS";

0 commit comments

Comments
 (0)