@nemu.pm/tachiyomi-runtime 0.1.0

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/src/types.ts ADDED
@@ -0,0 +1,211 @@
1
+ /**
2
+ * Core types for Tachiyomi extensions
3
+ */
4
+
5
+ // ============================================================================
6
+ // Manga & Chapter Types
7
+ // ============================================================================
8
+
9
+ export enum MangaStatus {
10
+ UNKNOWN = 0,
11
+ ONGOING = 1,
12
+ COMPLETED = 2,
13
+ LICENSED = 3,
14
+ PUBLISHING_FINISHED = 4,
15
+ CANCELLED = 5,
16
+ ON_HIATUS = 6,
17
+ }
18
+
19
+ export interface Manga {
20
+ url: string;
21
+ title: string;
22
+ artist?: string;
23
+ author?: string;
24
+ description?: string;
25
+ genre?: string[];
26
+ status: MangaStatus;
27
+ thumbnailUrl?: string;
28
+ initialized: boolean;
29
+ }
30
+
31
+ export interface Chapter {
32
+ url: string;
33
+ name: string;
34
+ dateUpload: number;
35
+ chapterNumber: number;
36
+ scanlator?: string;
37
+ }
38
+
39
+ export interface Page {
40
+ index: number;
41
+ url: string;
42
+ imageUrl?: string;
43
+ }
44
+
45
+ export interface MangasPage {
46
+ mangas: Manga[];
47
+ hasNextPage: boolean;
48
+ }
49
+
50
+ // ============================================================================
51
+ // Source & Extension Types
52
+ // ============================================================================
53
+
54
+ export interface SourceInfo {
55
+ id: string;
56
+ name: string;
57
+ lang: string;
58
+ baseUrl: string;
59
+ supportsLatest: boolean;
60
+ }
61
+
62
+ export interface ExtensionManifest {
63
+ id: string;
64
+ name: string;
65
+ pkg: string;
66
+ lang: string;
67
+ version: number;
68
+ nsfw: boolean;
69
+ hasWebView?: boolean;
70
+ hasCloudflare?: boolean;
71
+ icon?: string;
72
+ jsPath?: string;
73
+ sources: SourceInfo[];
74
+ authors?: Author[];
75
+ }
76
+
77
+ export interface Author {
78
+ name: string;
79
+ github?: string;
80
+ commits: number;
81
+ firstCommit: string;
82
+ }
83
+
84
+ // ============================================================================
85
+ // Filter Types (match Kotlin/JS output)
86
+ // ============================================================================
87
+
88
+ /** Header filter - section label, not interactive */
89
+ export interface FilterHeader {
90
+ type: 'Header';
91
+ name: string;
92
+ }
93
+
94
+ /** Separator filter - visual divider */
95
+ export interface FilterSeparator {
96
+ type: 'Separator';
97
+ name: string; // Usually empty
98
+ }
99
+
100
+ /** Text filter - free-form input */
101
+ export interface FilterText {
102
+ type: 'Text';
103
+ name: string;
104
+ state: string;
105
+ }
106
+
107
+ /** Checkbox filter - boolean toggle */
108
+ export interface FilterCheckBox {
109
+ type: 'CheckBox';
110
+ name: string;
111
+ state: boolean;
112
+ }
113
+
114
+ /** TriState filter - ignore/include/exclude */
115
+ export interface FilterTriState {
116
+ type: 'TriState';
117
+ name: string;
118
+ state: number; // 0=ignore, 1=include, 2=exclude
119
+ }
120
+
121
+ /** Sort filter - sorting options */
122
+ export interface FilterSort {
123
+ type: 'Sort';
124
+ name: string;
125
+ state: { index: number; ascending: boolean } | null;
126
+ values: string[];
127
+ }
128
+
129
+ /** Select filter - dropdown/single select */
130
+ export interface FilterSelect {
131
+ type: 'Select';
132
+ name: string;
133
+ state: number;
134
+ values: string[];
135
+ }
136
+
137
+ /** Group filter - container for child filters */
138
+ export interface FilterGroup {
139
+ type: 'Group';
140
+ name: string;
141
+ state: FilterState[]; // Nested filters
142
+ }
143
+
144
+ /** Union of all filter types */
145
+ export type FilterState =
146
+ | FilterHeader
147
+ | FilterSeparator
148
+ | FilterText
149
+ | FilterCheckBox
150
+ | FilterTriState
151
+ | FilterSort
152
+ | FilterSelect
153
+ | FilterGroup;
154
+
155
+ // ============================================================================
156
+ // Filter State Helpers
157
+ // ============================================================================
158
+
159
+ /** Minimal state update format for applyFilterState() */
160
+ export interface FilterStateUpdate {
161
+ index: number;
162
+ state?: boolean | number | string | { index: number; ascending: boolean };
163
+ filters?: FilterStateUpdate[]; // For Group filters
164
+ }
165
+
166
+ /** Convert a single filter to its state update format */
167
+ export function filterToStateUpdate(filter: FilterState, index: number): FilterStateUpdate | null {
168
+ switch (filter.type) {
169
+ case 'CheckBox':
170
+ return { index, state: filter.state };
171
+ case 'TriState':
172
+ return { index, state: filter.state };
173
+ case 'Text':
174
+ return filter.state ? { index, state: filter.state } : null;
175
+ case 'Select':
176
+ return { index, state: filter.state };
177
+ case 'Sort':
178
+ return filter.state ? { index, state: filter.state } : null;
179
+ case 'Group':
180
+ const childUpdates = filter.state
181
+ .map((f, i) => filterToStateUpdate(f, i))
182
+ .filter((u): u is FilterStateUpdate => u !== null);
183
+ return childUpdates.length > 0 ? { index, filters: childUpdates } : null;
184
+ default:
185
+ return null; // Header, Separator have no state
186
+ }
187
+ }
188
+
189
+ /** Convert filter list to JSON string for applyFilterState() */
190
+ export function buildFilterStateJson(filters: FilterState[]): string {
191
+ const updates = filters
192
+ .map((f, i) => filterToStateUpdate(f, i))
193
+ .filter((u): u is FilterStateUpdate => u !== null);
194
+ return JSON.stringify(updates);
195
+ }
196
+
197
+ // ============================================================================
198
+ // Settings Types
199
+ // ============================================================================
200
+
201
+ export interface SettingsSchema {
202
+ preferences: PreferenceSchema[];
203
+ }
204
+
205
+ export type PreferenceSchema =
206
+ | { type: 'EditTextPreference'; key: string; title: string; summary?: string; default?: string }
207
+ | { type: 'CheckBoxPreference'; key: string; title: string; summary?: string; default?: boolean }
208
+ | { type: 'ListPreference'; key: string; title: string; entries: string[]; entryValues: string[]; default?: string }
209
+ | { type: 'MultiSelectListPreference'; key: string; title: string; entries: string[]; entryValues: string[]; default?: string[] }
210
+ | { type: 'SwitchPreferenceCompat'; key: string; title: string; summary?: string; default?: boolean };
211
+