Skip to content

Commit a0ff3cf

Browse files
authored
🤖 Merge PR DefinitelyTyped#74390 Add Book interface to Kotobee types with detailed metadata structure by @Bashamega
1 parent 6d95ac3 commit a0ff3cf

2 files changed

Lines changed: 257 additions & 0 deletions

File tree

‎types/kotobee/index.d.ts‎

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,177 @@ type LanguageCode =
2424

2525
type Directions = "ltr" | "rtl";
2626

27+
/**
28+
* Represents the current state and metadata of the loaded eBook in the Kotobee Reader.
29+
*/
30+
interface Book {
31+
/**
32+
* Information about the current chapter.
33+
*/
34+
chapter: {
35+
/**
36+
* Whether this is not the last chapter.
37+
*/
38+
notLastChapter: boolean;
39+
/**
40+
* Whether this is not the first chapter.
41+
*/
42+
notFirstChapter: boolean;
43+
/**
44+
* Relative URL path of the current chapter.
45+
*/
46+
url: string;
47+
/**
48+
* Fully qualified URL for the current chapter.
49+
*/
50+
absoluteURL: string;
51+
/**
52+
* Title of the current chapter.
53+
*/
54+
title: string;
55+
/**
56+
* Viewport settings or null if not specified.
57+
*/
58+
viewport: null;
59+
/**
60+
* Layout type of the current chapter (e.g., 'reflowable' or 'fixed').
61+
*/
62+
layout: string;
63+
/**
64+
* Current view mode (e.g., 'single', 'double', 'scroll', etc.).
65+
*/
66+
view: string;
67+
/**
68+
* Indicates if the chapter is displayed in paged mode.
69+
*/
70+
paged: boolean;
71+
};
72+
/**
73+
* Metadata describing the book, compatible with various standards.
74+
*/
75+
meta: {
76+
/**
77+
* Dublin Core metadata fields.
78+
*/
79+
dc: {
80+
/**
81+
* The book's title.
82+
*/
83+
title: string;
84+
/**
85+
* Unique identifier for the book.
86+
*/
87+
identifier: string;
88+
/**
89+
* Publication identifier.
90+
*/
91+
"pub-id": string;
92+
/**
93+
* Book author/creator.
94+
*/
95+
creator: string;
96+
/**
97+
* Publisher's name.
98+
*/
99+
publisher: string;
100+
/**
101+
* Copyright or rights information.
102+
*/
103+
rights: string;
104+
language: LanguageCode;
105+
/**
106+
* Book description or summary.
107+
*/
108+
description: string;
109+
};
110+
/**
111+
* Cover image URL or path.
112+
*/
113+
cover: string;
114+
/**
115+
* DCMI Terms metadata.
116+
*/
117+
dcterms: {
118+
/**
119+
* Date and time of the last modification (ISO 8601).
120+
*/
121+
modified: string;
122+
};
123+
/**
124+
* Epub3 'rendition' metadata.
125+
*/
126+
rendition: {
127+
/**
128+
* Rendering/layout mode ("reflowable", "pre-paginated", etc.).
129+
*/
130+
layout: string;
131+
/**
132+
* Device orientation ("portrait", "landscape", etc.).
133+
*/
134+
orientation: string;
135+
};
136+
/**
137+
* Apple Books (iBooks) specific metadata.
138+
*/
139+
ibooks: {
140+
/**
141+
* Whether the book is interactive ("true" or "false").
142+
*/
143+
interactive: "true" | "false";
144+
/**
145+
* Whether specified fonts are used ("true" or "false").
146+
*/
147+
"specified-fonts": "true" | "false";
148+
};
149+
/**
150+
* Kotobee-specific metadata.
151+
*/
152+
kotobee: {
153+
/**
154+
* Kotobee reader version.
155+
*/
156+
version: string;
157+
/**
158+
* Kotobee reader build number.
159+
*/
160+
build: string;
161+
};
162+
/**
163+
* Schema.org accessibility metadata.
164+
*/
165+
schema: {
166+
/**
167+
* The access mode (e.g., "textual", "visual").
168+
*/
169+
accessmode: string;
170+
/**
171+
* Sufficient access modes ("textual", "visual", etc.).
172+
*/
173+
accessmodesufficient: string;
174+
/**
175+
* Accessibility feature (e.g., "structuralNavigation").
176+
*/
177+
accessibilityfeature: string;
178+
/**
179+
* Accessibility hazards ("none", "flashing", etc.).
180+
*/
181+
accessibilityhazard: string;
182+
/**
183+
* Summary of the book's accessibility features.
184+
*/
185+
accessibilitysummary: string;
186+
};
187+
};
188+
/**
189+
* Kotobee Book structure version.
190+
*/
191+
version: number;
192+
/**
193+
* Book chapters serialized as a string (usually JSON or XML).
194+
*/
195+
chapters: string;
196+
}
197+
27198
interface KotobeeReader {
28199
/**
29200
* Clears cached local data used by the reader.
@@ -49,6 +220,7 @@ interface KotobeeReader {
49220
* Sets reading direction (left-to-right or right-to-left).
50221
*/
51222
setDirection: (direction: Directions) => void;
223+
book: Book;
52224
}
53225

54226
// Declare the global variable

‎types/kotobee/kotobee-tests.ts‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,88 @@ validDirections.forEach(dir => {
6666
const fakeLang: LanguageCode = "madeup";
6767
// @ts-expect-error
6868
const dirCenter: Directions = "center";
69+
70+
// ------------------- Book Interface Tests -------------------
71+
72+
const book: Book = {
73+
chapter: {
74+
notLastChapter: true,
75+
notFirstChapter: false,
76+
url: "chapter1.xhtml",
77+
absoluteURL: "https://example.com/chapter1.xhtml",
78+
title: "Introduction",
79+
viewport: null,
80+
layout: "reflowable",
81+
view: "single",
82+
paged: true,
83+
},
84+
meta: {
85+
dc: {
86+
title: "Sample Book",
87+
identifier: "abc-123",
88+
"pub-id": "pub-456",
89+
creator: "Jane Doe",
90+
publisher: "Book Publisher",
91+
rights: "© 2024 Jane Doe",
92+
language: "en",
93+
description: "A fascinating sample book.",
94+
},
95+
cover: "cover.jpg",
96+
dcterms: {
97+
modified: "2023-07-01T12:00:00Z",
98+
},
99+
rendition: {
100+
layout: "reflowable",
101+
orientation: "portrait",
102+
},
103+
ibooks: {
104+
interactive: "true",
105+
"specified-fonts": "false",
106+
},
107+
kotobee: {
108+
version: "2.1.4",
109+
build: "12384",
110+
},
111+
schema: {
112+
accessmode: "textual",
113+
accessmodesufficient: "textual",
114+
accessibilityfeature: "structuralNavigation",
115+
accessibilityhazard: "none",
116+
accessibilitysummary: "Accessible for screen readers.",
117+
},
118+
},
119+
version: 2,
120+
chapters:
121+
`<li class="item parent"><i class="icon parent"> </i> <a href="#/reader/chapter/0" data-url="xhtml/raw/ch1.xhtml">Page 1</a></li>
122+
<li class="item"><i class="icon"> </i> <a href="#/reader/chapter/1" data-url="xhtml/raw/ch2.xhtml">Page 2</a></li>`,
123+
};
124+
125+
// Book with missing required properties - should error
126+
// @ts-expect-error
127+
const incompleteBook: Book = {};
128+
129+
// Invalid type in Book.meta.dc.language - should error
130+
const bookWithInvalidLang: Book = {
131+
...book,
132+
meta: {
133+
...book.meta,
134+
dc: {
135+
...book.meta.dc,
136+
// @ts-expect-error
137+
language: "not-a-language",
138+
},
139+
},
140+
};
141+
142+
// Invalid interactive field in ibooks - should error
143+
const bookWithInvalidIbooks: Book = {
144+
...book,
145+
meta: {
146+
...book.meta,
147+
ibooks: {
148+
// @ts-expect-error
149+
interactive: "sometimes",
150+
"specified-fonts": "true",
151+
},
152+
},
153+
};

0 commit comments

Comments
 (0)