@quran.ws/qvp-react-native 0.6.1 → 0.8.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/README.md +66 -6
- package/android/build.gradle +1 -0
- package/android/src/main/java/ws/quran/qvp/rn/Codes.kt +34 -0
- package/android/src/main/java/ws/quran/qvp/rn/Marshal.kt +128 -30
- package/android/src/main/java/ws/quran/qvp/rn/QvpModule.kt +149 -50
- package/android/src/main/java/ws/quran/qvp/rn/QvpPackage.kt +1 -1
- package/android/src/main/java/ws/quran/qvp/rn/QvpPageViewManager.kt +4 -6
- package/android/src/main/java/ws/quran/qvp/rn/QvpPassageViewManager.kt +39 -0
- package/android/src/main/java/ws/quran/qvp/rn/QvpRnBytes.kt +20 -0
- package/android/src/main/java/ws/quran/qvp/rn/QvpRnEvents.kt +28 -0
- package/android/src/main/java/ws/quran/qvp/rn/QvpRnPageView.kt +87 -41
- package/android/src/main/java/ws/quran/qvp/rn/QvpRnPassageView.kt +144 -0
- package/android/src/main/java/ws/quran/qvp/rn/QvpRnWords.kt +26 -0
- package/package.json +2 -1
- package/src/codes.ts +33 -0
- package/src/index.tsx +288 -48
package/README.md
CHANGED
|
@@ -88,6 +88,52 @@ Colours: `'#rgb' | '#rrggbb' | '#rrggbbaa' | 0xRRGGBBAA` (`css()` / `rgba(c, alp
|
|
|
88
88
|
Targets: `'page' | '2:255' | '2:255:3' | '2:255-257' | 'line:7' | 'surah:2' | wordIdx | [index…] | T.*`.
|
|
89
89
|
Selectors: `Sel.page/path/wordPath/wordMark/wordMarkNamed/wordBody/wordMarks/word/ayah/line/mark/category/family/kind/decoration/decorationIndex`.
|
|
90
90
|
|
|
91
|
+
## The passage view
|
|
92
|
+
|
|
93
|
+
A passage is a range of complete ayahs shown away from its page, or a surah's basmalah. The
|
|
94
|
+
engine lays it out on rows of the view's width and the view draws it; the layout comes back
|
|
95
|
+
through `onPassageLayout`, and the view takes its height from it.
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
<QvpPassageView
|
|
99
|
+
style={{ width: '100%' }}
|
|
100
|
+
pageUris={['asset://pages/042.qvp']} // the pages that print the range, in any order
|
|
101
|
+
surah={2} from={255} // to={…} for a range; basmalah for the surah's basmalah
|
|
102
|
+
lineHeight={22} // dp per printed line (or scale: dp per page unit)
|
|
103
|
+
align="justified" maxStretch={2} // right (the default), center or justified
|
|
104
|
+
maxRows={2} ellipsisWidth={12} keepAyahMark // cut after two rows, ellipsis, then the medallion
|
|
105
|
+
ink="#231f20" paperColor="#fffdf7"
|
|
106
|
+
onPassageLayout={l => console.log(l.rows.length, l.words.length, l.isTruncated)}
|
|
107
|
+
/>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Dress
|
|
111
|
+
|
|
112
|
+
A page can wear another mushaf's ornaments: an ayah medallion, a surah band and a page border
|
|
113
|
+
from an ornament set (`ornaments.qvo`, in the data release). The engine places each ornament.
|
|
114
|
+
The native view paints the layer behind the ink and fits the border into the view.
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
const set = await QvpOrnaments.load('asset://pages/ornaments.qvo');
|
|
118
|
+
const medallion = await set.find('ayah_mark', 'font-003-regular');
|
|
119
|
+
<QvpPageView
|
|
120
|
+
pageUri="asset://pages/604.qvp"
|
|
121
|
+
dress={{ ornaments: set, style: 'mushaf-qalon', ayahMark: medallion, gap: 5, lineArt: ['surah_header'] }}
|
|
122
|
+
onDressChanged={({ info }) => console.log(info?.ayahMarks, info?.frameRepeats)} // null: refused
|
|
123
|
+
/>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
- `style` takes a mushaf's medallion, band and border together. A kind key (`ayahMark`,
|
|
127
|
+
`surahHeader`, `pageFrame`) overrides the style for that kind. It takes an ornament, an
|
|
128
|
+
index or a style name. `null` is none.
|
|
129
|
+
- The knobs are `gap`, `bandGap`, `ayahMarkScale` (0 takes the design's own size),
|
|
130
|
+
`pageFrameScale`, `lineArt` (`true` or a list of kinds) and `colors` (`[ornament, part, colour]`).
|
|
131
|
+
- `set.list` gives each ornament with its `licence` and `parts`. `set.styles()` groups the
|
|
132
|
+
ornaments by mushaf, and `set.ofKind(kind)` filters them. Read the licence before you
|
|
133
|
+
publish a dressed page.
|
|
134
|
+
- The prop dresses every page the view loads. `qvp.dress(set, spec)`, `qvp.undress()`,
|
|
135
|
+
`qvp.dressInfo()` and `qvp.dressRevision()` act on the page in the view now. Do not mix them with the `dress` prop on one view.
|
|
136
|
+
|
|
91
137
|
## The module
|
|
92
138
|
|
|
93
139
|
Everything takes the view's react tag (`findNodeHandle`) — or use the bound forms:
|
|
@@ -123,9 +169,17 @@ await atlas.pagesOfJuz(30); atlas.searchSurahs('cow' | 'البقرة' | '2'); at
|
|
|
123
169
|
// tag-level equivalents: Qvp.atlasPageOf(id, s, a), Qvp.atlasSearchSurahs(id, text), Qvp.atlasPagesOfJuz(id, n), Qvp.atlasJuzOf(id, s, a), …
|
|
124
170
|
```
|
|
125
171
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
172
|
+
The module runs a call on one of two threads. Its own query thread runs each call that reads only
|
|
173
|
+
what a page fixed when it loaded: `info`, `words`, `word`, `ayahs`, `lines`, `decorations`, `findWord`,
|
|
174
|
+
`targetWords`, `wordForm`, `hasForm`, the metadata calls except `surahHeaders` and `surahHeadersView`,
|
|
175
|
+
`text`, `search`, `citation`, `cropBounds`, `grid`, the engine-wide helpers and the atlas. A long call
|
|
176
|
+
there does not hold up a frame. The view keeps its page open until such a call returns. Every other
|
|
177
|
+
call reads or changes the layout, the view, the styles or the page state, and runs on the UI thread,
|
|
178
|
+
where the view draws. `attachWords` runs on the UI thread after the queries queued before it, and the
|
|
179
|
+
queries queued after it wait for it.
|
|
180
|
+
|
|
181
|
+
`words` builds each word's record once per page: its forms, its label and the names of its paths.
|
|
182
|
+
A later call sends the same records again, and `attachWords` drops them.
|
|
129
183
|
|
|
130
184
|
## Layout of this package
|
|
131
185
|
|
|
@@ -134,17 +188,23 @@ android/build.gradle library module; depends on project(':
|
|
|
134
188
|
android/src/main/java/ws/quran/qvp/rn/
|
|
135
189
|
QvpRnPageView.kt QvpPageView subclass: page loading, prop → handle reconciliation, events
|
|
136
190
|
QvpPageViewManager.kt SimpleViewManager<QvpRnPageView> (props, events, commit after each prop batch)
|
|
137
|
-
|
|
191
|
+
QvpRnPassageView.kt View: loads the pages, lays the passage out at the view's width, draws it, reports the layout
|
|
192
|
+
QvpPassageViewManager.kt SimpleViewManager<QvpRnPassageView>
|
|
193
|
+
QvpRnBytes.kt the bytes a URI names (asset, file, path, base64)
|
|
194
|
+
QvpModule.kt ReactContextBaseJavaModule: page queries by react tag, engine helpers, atlas, ornament sets
|
|
138
195
|
Marshal.kt JS shapes ↔ Kotlin types (targets, selectors, styles, records)
|
|
196
|
+
QvpRnWords.kt each word's record, built once per page
|
|
197
|
+
Codes.kt QVP_TARGET_* and QVP_SELECTOR_* by name (scripts/gen-rn-enums.py writes it)
|
|
139
198
|
QvpPackage.kt
|
|
140
|
-
src/index.tsx typed API: <QvpPageView/>, useQvp(), Qvp, QvpAtlas, Sel, T, constants
|
|
199
|
+
src/index.tsx typed API: <QvpPageView/>, <QvpPassageView/>, useQvp(), Qvp, QvpAtlas, QvpOrnaments, Sel, T, constants
|
|
200
|
+
src/codes.ts the same codes for T and Sel (scripts/gen-rn-enums.py writes it)
|
|
141
201
|
```
|
|
142
202
|
|
|
143
203
|
## iOS — TODO
|
|
144
204
|
|
|
145
205
|
Not implemented (no macOS in the build environment). The iOS side mirrors the Android module over the
|
|
146
206
|
same `qvp.h`: a Swift `QvpPage`/`QvpAtlas` over `libqvp_ffi.a` (build with
|
|
147
|
-
`cargo build -p qvp-ffi --
|
|
207
|
+
`cargo build -p qvp-ffi --profile dist --target aarch64-apple-ios[-sim]`), a `UIView` renderer with the
|
|
148
208
|
same draw order (highlight bands → cached base ink → styled ink → mask boxes, `tick(now)` per
|
|
149
209
|
`CADisplayLink` frame), an `RCTViewManager` exposing the props above with the same reconciliation, and
|
|
150
210
|
an `RCTBridgeModule` with the same method names. `src/index.tsx` needs no changes.
|
package/android/build.gradle
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Generated by scripts/gen-rn-enums.py from crates/qvp-ffi/include/qvp.h. Do not edit.
|
|
2
|
+
package ws.quran.qvp.rn
|
|
3
|
+
|
|
4
|
+
/** The QVP_TARGET_* and QVP_SELECTOR_* codes, and each code by its JavaScript name. */
|
|
5
|
+
object Codes {
|
|
6
|
+
const val TARGET_PAGE = 0
|
|
7
|
+
const val TARGET_WORD = 1
|
|
8
|
+
const val TARGET_WORDS = 2
|
|
9
|
+
const val TARGET_AYAH = 3
|
|
10
|
+
const val TARGET_AYAH_RANGE = 4
|
|
11
|
+
const val TARGET_LINE = 5
|
|
12
|
+
const val TARGET_SURAH = 6
|
|
13
|
+
const val TARGET_RANGE = 7
|
|
14
|
+
/** QVP_TARGET_*: the kind of a target, by name. */
|
|
15
|
+
val TARGETS: Map<String, Int> = mapOf("page" to TARGET_PAGE, "word" to TARGET_WORD, "words" to TARGET_WORDS, "ayah" to TARGET_AYAH, "ayahRange" to TARGET_AYAH_RANGE, "line" to TARGET_LINE, "surah" to TARGET_SURAH, "range" to TARGET_RANGE)
|
|
16
|
+
const val SELECTOR_PAGE = 0
|
|
17
|
+
const val SELECTOR_PATH = 1
|
|
18
|
+
const val SELECTOR_WORD_PATH = 2
|
|
19
|
+
const val SELECTOR_WORD_MARK = 3
|
|
20
|
+
const val SELECTOR_WORD_MARK_NAMED = 4
|
|
21
|
+
const val SELECTOR_WORD_BODY = 5
|
|
22
|
+
const val SELECTOR_WORD_MARKS = 6
|
|
23
|
+
const val SELECTOR_WORD = 7
|
|
24
|
+
const val SELECTOR_AYAH = 8
|
|
25
|
+
const val SELECTOR_LINE = 9
|
|
26
|
+
const val SELECTOR_MARK = 10
|
|
27
|
+
const val SELECTOR_CATEGORY = 11
|
|
28
|
+
const val SELECTOR_FAMILY = 12
|
|
29
|
+
const val SELECTOR_KIND = 13
|
|
30
|
+
const val SELECTOR_DECORATION = 14
|
|
31
|
+
const val SELECTOR_DECORATION_INDEX = 15
|
|
32
|
+
/** QVP_SELECTOR_*: the kind of a selector, by name. */
|
|
33
|
+
val SELECTORS: Map<String, Int> = mapOf("page" to SELECTOR_PAGE, "path" to SELECTOR_PATH, "wordPath" to SELECTOR_WORD_PATH, "wordMark" to SELECTOR_WORD_MARK, "wordMarkNamed" to SELECTOR_WORD_MARK_NAMED, "wordBody" to SELECTOR_WORD_BODY, "wordMarks" to SELECTOR_WORD_MARKS, "word" to SELECTOR_WORD, "ayah" to SELECTOR_AYAH, "line" to SELECTOR_LINE, "mark" to SELECTOR_MARK, "category" to SELECTOR_CATEGORY, "family" to SELECTOR_FAMILY, "kind" to SELECTOR_KIND, "decoration" to SELECTOR_DECORATION, "decorationIndex" to SELECTOR_DECORATION_INDEX)
|
|
34
|
+
}
|
|
@@ -13,8 +13,8 @@ import ws.quran.qvp.Target
|
|
|
13
13
|
* styling decisions live here — every call goes to [QvpPage] / [QvpAtlas], which go to the engine.
|
|
14
14
|
*
|
|
15
15
|
* Targets from JS: "page" | "2:255" | "2:255:3" | "2:255-257" | "line:7" | "surah:2" | word index |
|
|
16
|
-
* [word indices] | {target, a, b, c, words} (target = QVP_TARGET_* or its name).
|
|
17
|
-
* Selectors from JS: {selector, a, b, c} (selector = QVP_SELECTOR_* or its name). Colours: '#rgb' | '#rrggbb' | '#rrggbbaa'.
|
|
16
|
+
* [word indices] | {target, a, b, c, words} (target = QVP_TARGET_* or its name in [Codes]).
|
|
17
|
+
* Selectors from JS: {selector, a, b, c} (selector = QVP_SELECTOR_* or its name in [Codes]). Colours: '#rgb' | '#rrggbb' | '#rrggbbaa'.
|
|
18
18
|
*/
|
|
19
19
|
object Marshal {
|
|
20
20
|
// ── colours ──
|
|
@@ -36,11 +36,10 @@ object Marshal {
|
|
|
36
36
|
else -> IntArray(0)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
private
|
|
41
|
-
private fun kindOf(v: Any?, names: List<String>): Int = when (v) {
|
|
39
|
+
/** A code given as a number, or by its name in [names] (or as a numeral); -1 when neither. */
|
|
40
|
+
private fun codeOf(v: Any?, names: Map<String, Int>): Int = when (v) {
|
|
42
41
|
is Number -> v.toInt()
|
|
43
|
-
is String -> names
|
|
42
|
+
is String -> names[v] ?: v.toIntOrNull() ?: -1
|
|
44
43
|
else -> -1
|
|
45
44
|
}
|
|
46
45
|
|
|
@@ -53,9 +52,15 @@ object Marshal {
|
|
|
53
52
|
is IntArray -> Target.words(v)
|
|
54
53
|
is Map<*, *> -> {
|
|
55
54
|
val a = num(v["a"]) ?: 0; val b = num(v["b"]) ?: 0; val c = num(v["c"]) ?: 0
|
|
56
|
-
when (
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
when (codeOf(v["target"], Codes.TARGETS)) {
|
|
56
|
+
Codes.TARGET_PAGE -> Target.page()
|
|
57
|
+
Codes.TARGET_WORD -> Target.word(a)
|
|
58
|
+
Codes.TARGET_WORDS -> Target.words(ints(v["words"] ?: v["a"]))
|
|
59
|
+
Codes.TARGET_AYAH -> Target.ayah(a, b)
|
|
60
|
+
Codes.TARGET_AYAH_RANGE -> Target.ayahRange(a, b, c)
|
|
61
|
+
Codes.TARGET_LINE -> Target.line(a)
|
|
62
|
+
Codes.TARGET_SURAH -> Target.surah(a)
|
|
63
|
+
Codes.TARGET_RANGE -> Target.range(a, b)
|
|
59
64
|
else -> Target.words(IntArray(0))
|
|
60
65
|
}
|
|
61
66
|
}
|
|
@@ -66,34 +71,57 @@ object Marshal {
|
|
|
66
71
|
fun selector(v: Any?): Selector? {
|
|
67
72
|
val m = v as? Map<*, *> ?: return null
|
|
68
73
|
val a = num(m["a"]) ?: 0; val b = num(m["b"]) ?: 0; val c = num(m["c"]) ?: 0
|
|
69
|
-
return when (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
return when (codeOf(m["selector"], Codes.SELECTORS)) {
|
|
75
|
+
Codes.SELECTOR_PAGE -> Selector.page()
|
|
76
|
+
Codes.SELECTOR_PATH -> Selector.path(a)
|
|
77
|
+
Codes.SELECTOR_WORD_PATH -> Selector.wordPath(a, b)
|
|
78
|
+
Codes.SELECTOR_WORD_MARK -> Selector.wordMark(a, b)
|
|
79
|
+
Codes.SELECTOR_WORD_MARK_NAMED -> Selector.wordMarkNamed(a, (m["mark"] as? String) ?: QvpEngine.markName(b), c)
|
|
80
|
+
Codes.SELECTOR_WORD_BODY -> Selector.wordBody(a)
|
|
81
|
+
Codes.SELECTOR_WORD_MARKS -> Selector.wordMarks(a)
|
|
82
|
+
Codes.SELECTOR_WORD -> Selector.word(a)
|
|
83
|
+
Codes.SELECTOR_AYAH -> Selector.ayah(a, b)
|
|
84
|
+
Codes.SELECTOR_LINE -> Selector.line(a)
|
|
85
|
+
Codes.SELECTOR_MARK -> (m["mark"] as? String)?.let { Selector.mark(it) } ?: Selector.mark(a)
|
|
86
|
+
Codes.SELECTOR_CATEGORY -> Selector.category(a)
|
|
87
|
+
Codes.SELECTOR_FAMILY -> Selector.family(a)
|
|
88
|
+
Codes.SELECTOR_KIND -> Selector.kind(a)
|
|
89
|
+
Codes.SELECTOR_DECORATION -> Selector.decoration(a)
|
|
90
|
+
Codes.SELECTOR_DECORATION_INDEX -> Selector.decorationIndex(a)
|
|
75
91
|
else -> null
|
|
76
92
|
}
|
|
77
93
|
}
|
|
78
94
|
|
|
95
|
+
/** The constant of [entries] that [v] names, in any of its spellings: the constant's own
|
|
96
|
+
* (RASM_IMLAI), snake case (rasm_imlai) or the camelCase of the TypeScript types (rasmImlai). */
|
|
97
|
+
private fun <E : Enum<E>> named(entries: List<E>, v: String): E? {
|
|
98
|
+
val key = v.replace("_", "")
|
|
99
|
+
return entries.firstOrNull { it.name.replace("_", "").equals(key, ignoreCase = true) }
|
|
100
|
+
}
|
|
101
|
+
/** A constant's name as the TypeScript types spell it: RASM_IMLAI is rasmImlai. */
|
|
102
|
+
fun jsName(e: Enum<*>): String {
|
|
103
|
+
val parts = e.name.lowercase().split('_')
|
|
104
|
+
return parts[0] + parts.drop(1).joinToString("") { it.replaceFirstChar(Char::uppercaseChar) }
|
|
105
|
+
}
|
|
106
|
+
|
|
79
107
|
fun form(v: Any?, d: Form = Form.RASM_UTHMANI): Form = when (v) {
|
|
80
108
|
is Number -> Form.entries.getOrElse(v.toInt()) { d }
|
|
81
|
-
is String -> Form.entries
|
|
109
|
+
is String -> named(Form.entries, v) ?: d
|
|
82
110
|
else -> d
|
|
83
111
|
}
|
|
84
112
|
fun searchMode(v: Any?): SearchMode = when (v) {
|
|
85
113
|
is Number -> SearchMode.entries.getOrElse(v.toInt()) { SearchMode.INCLUDES }
|
|
86
|
-
is String -> SearchMode.entries
|
|
114
|
+
is String -> named(SearchMode.entries, v) ?: SearchMode.INCLUDES
|
|
87
115
|
else -> SearchMode.INCLUDES
|
|
88
116
|
}
|
|
89
117
|
fun maskMode(v: Any?): MaskMode = when (v) {
|
|
90
118
|
is Number -> MaskMode.entries.getOrElse(v.toInt()) { MaskMode.HIDE }
|
|
91
|
-
is String -> MaskMode.entries
|
|
119
|
+
is String -> named(MaskMode.entries, v) ?: MaskMode.HIDE
|
|
92
120
|
else -> MaskMode.HIDE
|
|
93
121
|
}
|
|
94
122
|
fun division(v: Any?): Division = when (v) {
|
|
95
123
|
is Number -> Division.entries.getOrElse(v.toInt()) { Division.JUZ }
|
|
96
|
-
is String -> Division.entries
|
|
124
|
+
is String -> named(Division.entries, v) ?: Division.JUZ
|
|
97
125
|
else -> Division.JUZ
|
|
98
126
|
}
|
|
99
127
|
|
|
@@ -101,8 +129,8 @@ object Marshal {
|
|
|
101
129
|
fun highlightStyle(v: Any?): QvpHighlightStyle {
|
|
102
130
|
val m = v as? Map<*, *> ?: return QvpHighlightStyle()
|
|
103
131
|
val d = QvpHighlightStyle()
|
|
104
|
-
val mode = when (val x = m["mode"]) { is Number -> HighlightMode.entries.getOrElse(x.toInt()) { d.mode }; is String -> HighlightMode.entries
|
|
105
|
-
val height = when (val x = m["height"]) { is Number -> BandHeight.entries.getOrElse(x.toInt()) { d.height }; is String -> BandHeight.entries
|
|
132
|
+
val mode = when (val x = m["mode"]) { is Number -> HighlightMode.entries.getOrElse(x.toInt()) { d.mode }; is String -> named(HighlightMode.entries, x) ?: d.mode; else -> d.mode }
|
|
133
|
+
val height = when (val x = m["height"]) { is Number -> BandHeight.entries.getOrElse(x.toInt()) { d.height }; is String -> named(BandHeight.entries, x) ?: d.height; else -> d.height }
|
|
106
134
|
return QvpHighlightStyle(mode = mode, ink = color(m["ink"], d.ink), band = color(m["band"], d.band), height = height, padX = flt(m["padX"], d.padX), padY = flt(m["padY"], d.padY),
|
|
107
135
|
radius = flt(m["radius"], d.radius), seam = flt(m["seam"], d.seam), transitionMs = num(m["ms"] ?: m["transitionMs"]) ?: d.transitionMs, layer = num(m["layer"]) ?: d.layer)
|
|
108
136
|
}
|
|
@@ -114,20 +142,83 @@ object Marshal {
|
|
|
114
142
|
ayahMark = colorOrNull(m["ayahMark"]), numeral = colorOrNull(m["numeral"]), headers = colorOrNull(m["headers"]), marks = marks, transitionMs = num(m["ms"] ?: m["transitionMs"]) ?: 0)
|
|
115
143
|
}
|
|
116
144
|
|
|
145
|
+
// ── dress ──
|
|
146
|
+
private val ORNAMENT_KINDS = QvpOrnamentKind.entries.associateBy { it.name.lowercase() }
|
|
147
|
+
/** 'ayah_mark' | 'surah_header' | 'page_frame' (or QVP_ORNAMENT_*) → [QvpOrnamentKind], or null. */
|
|
148
|
+
fun ornamentKind(v: Any?): QvpOrnamentKind? = when (v) {
|
|
149
|
+
is String -> ORNAMENT_KINDS[v.lowercase()]
|
|
150
|
+
is Number -> QvpOrnamentKind.entries.getOrNull(v.toInt())
|
|
151
|
+
else -> null
|
|
152
|
+
}
|
|
153
|
+
/** One kind of a JS spec: an index, a style name, or null for none (JS has already put the style in each kind). */
|
|
154
|
+
private fun ornamentRef(v: Any?): QvpOrnamentRef = when (v) {
|
|
155
|
+
is Number -> QvpOrnamentRef.Index(v.toInt())
|
|
156
|
+
is String -> QvpOrnamentRef.Style(v)
|
|
157
|
+
else -> QvpOrnamentRef.None
|
|
158
|
+
}
|
|
159
|
+
/** {ayahMark, surahHeader, pageFrame, gap, bandGap, ayahMarkScale, pageFrameScale, lineArt: [kind], colors: [[ornament, part, colour]]} → [QvpDressSpec].
|
|
160
|
+
* A missing number keeps the library's default. A missing kind draws none. */
|
|
161
|
+
fun dressSpec(v: Any?): QvpDressSpec {
|
|
162
|
+
val m = v as? Map<*, *> ?: return QvpDressSpec()
|
|
163
|
+
val d = QvpDressSpec()
|
|
164
|
+
val lineArt = (m["lineArt"] as? Iterable<*>)?.mapNotNull { ornamentKind(it) }?.toSet() ?: emptySet()
|
|
165
|
+
val colors = (m["colors"] as? Iterable<*>)?.mapNotNull { t ->
|
|
166
|
+
val l = (t as? Iterable<*>)?.toList() ?: return@mapNotNull null
|
|
167
|
+
val o = num(l.getOrNull(0)) ?: return@mapNotNull null
|
|
168
|
+
val part = num(l.getOrNull(1)) ?: return@mapNotNull null
|
|
169
|
+
QvpPartColor(o, part, color(l.getOrNull(2), 0))
|
|
170
|
+
} ?: emptyList()
|
|
171
|
+
return QvpDressSpec(style = null, ayahMark = ornamentRef(m["ayahMark"]), surahHeader = ornamentRef(m["surahHeader"]), pageFrame = ornamentRef(m["pageFrame"]),
|
|
172
|
+
gap = flt(m["gap"], d.gap), bandGap = flt(m["bandGap"], d.bandGap), ayahMarkScale = flt(m["ayahMarkScale"], d.ayahMarkScale),
|
|
173
|
+
pageFrameScale = flt(m["pageFrameScale"], d.pageFrameScale), lineArt = lineArt, colors = colors)
|
|
174
|
+
}
|
|
175
|
+
/** 0xRRGGBBAA as JS reads it: unsigned. */
|
|
176
|
+
private fun rgbaJs(c: Int): Long = c.toLong() and 0xffffffffL
|
|
177
|
+
fun ornamentPart(p: QvpOrnamentPart): Map<String, Any?> = mapOf("index" to p.index, "color" to rgbaJs(p.color), "stroke" to p.stroke, "name" to p.name)
|
|
178
|
+
fun ornament(o: QvpOrnament): Map<String, Any?> = mapOf("index" to o.index, "kind" to o.kind.name.lowercase(), "lineage" to o.lineage.name.lowercase(),
|
|
179
|
+
"style" to o.style, "riwayah" to o.riwayah, "hasSlices" to o.hasSlices,
|
|
180
|
+
"licence" to mapOf("id" to o.licence.id, "status" to o.licence.status, "redistributable" to o.licence.redistributable, "attribution" to o.licence.attribution),
|
|
181
|
+
"parts" to o.parts.map { ornamentPart(it) })
|
|
182
|
+
fun dressInfo(i: QvpDressInfo): Map<String, Any?> = mapOf("ayahMark" to i.ayahMark, "surahHeader" to i.surahHeader, "pageFrame" to i.pageFrame,
|
|
183
|
+
"ayahMarks" to i.ayahMarks, "surahHeaders" to i.surahHeaders, "frameRepeats" to i.frameRepeats, "frameStretched" to i.frameStretched,
|
|
184
|
+
"draws" to i.draws, "revision" to i.revision,
|
|
185
|
+
"viewBox" to listOf(i.viewBox.x, i.viewBox.y, i.viewBox.width, i.viewBox.height),
|
|
186
|
+
"overflow" to listOf(i.overflow.left, i.overflow.top, i.overflow.right, i.overflow.bottom))
|
|
187
|
+
|
|
117
188
|
// ── Kotlin → JS ──
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
189
|
+
/**
|
|
190
|
+
* The engine's name of every id of the path and decoration tables, read once. A page has
|
|
191
|
+
* hundreds of paths, and each names its kind, mark, category and family: a lookup here is
|
|
192
|
+
* an array read, not four calls into the engine. Ids run 0..255, so the table covers every
|
|
193
|
+
* id a path can hold, and an id the engine does not know gets the engine's own answer.
|
|
194
|
+
*/
|
|
195
|
+
private class Names {
|
|
196
|
+
val kind = Array(256) { QvpEngine.kindName(it) }
|
|
197
|
+
val mark = Array(256) { QvpEngine.markName(it) }
|
|
198
|
+
val category = Array(256) { QvpEngine.categoryName(it) }
|
|
199
|
+
val family = Array(256) { QvpEngine.familyName(it) }
|
|
200
|
+
val decoration = Array(256) { QvpEngine.decorationName(it).ifEmpty { "other" } }
|
|
201
|
+
}
|
|
202
|
+
private val names by lazy { Names() }
|
|
203
|
+
|
|
204
|
+
/** The forms a page has: [Form.RASM_UTHMANI] always, and each other form the words sidecar gave. */
|
|
205
|
+
fun forms(p: QvpPage): List<Form> = Form.entries.filter { it == Form.RASM_UTHMANI || p.hasForm(it) }
|
|
206
|
+
|
|
207
|
+
/** One word and its paths. [forms] is [forms] of the page, read once by the caller. */
|
|
208
|
+
fun word(p: QvpPage, w: QvpWord, forms: List<Form>): Map<String, Any?> {
|
|
209
|
+
val n = names
|
|
210
|
+
val text = LinkedHashMap<String, String>()
|
|
211
|
+
for (f in forms) text[jsName(f)] = p.wordForm(w.index, f)
|
|
121
212
|
val paths = (w.firstPath until w.firstPath + w.nPaths).map { i ->
|
|
122
213
|
val kind = p.pathKind(i); val mark = p.pathMark(i); val cat = p.pathCategory(i); val fam = p.pathFamily(i)
|
|
123
|
-
mapOf("index" to i, "kind" to kind, "kindName" to
|
|
124
|
-
"nthInWord" to p.pathNthInWord(i), "category" to cat, "categoryName" to
|
|
214
|
+
mapOf("index" to i, "kind" to kind, "kindName" to n.kind[kind], "mark" to mark, "markName" to n.mark[mark], "nthMark" to p.pathNthMark(i),
|
|
215
|
+
"nthInWord" to p.pathNthInWord(i), "category" to cat, "categoryName" to n.category[cat], "family" to fam, "familyName" to n.family[fam], "line" to p.pathLine(i))
|
|
125
216
|
}
|
|
126
217
|
return mapOf("index" to w.index, "surah" to w.surah, "ayah" to w.ayah, "word" to w.word, "line" to w.line, "lineIndex" to w.lineIndex, "ayahIndex" to w.ayahIndex,
|
|
127
218
|
"x0" to w.x0, "y0" to w.y0, "x1" to w.x1, "y1" to w.y1, "text" to w.text, "firstPath" to w.firstPath, "nPaths" to w.nPaths,
|
|
128
|
-
"wordKey" to w.wordKey, "ayahKey" to w.ayahKey, "forms" to
|
|
219
|
+
"wordKey" to w.wordKey, "ayahKey" to w.ayahKey, "forms" to text, "label" to p.wordLabel(w.index), "paths" to paths)
|
|
129
220
|
}
|
|
130
|
-
fun decoration(d: QvpDecoration): Map<String, Any?> = mapOf("index" to d.index, "decoration" to d.decoration, "decorationName" to
|
|
221
|
+
fun decoration(d: QvpDecoration): Map<String, Any?> = mapOf("index" to d.index, "decoration" to d.decoration, "decorationName" to names.decoration[d.decoration and 0xff],
|
|
131
222
|
"surah" to d.surah, "ayah" to d.ayah, "line" to d.line, "x0" to d.x0, "y0" to d.y0, "x1" to d.x1, "y1" to d.y1, "text" to d.text, "firstPath" to d.firstPath, "nPaths" to d.nPaths)
|
|
132
223
|
fun hit(p: QvpPage, h: QvpHit): Map<String, Any?> {
|
|
133
224
|
val w = if (h.word >= 0) p.words[h.word] else null
|
|
@@ -145,13 +236,20 @@ object Marshal {
|
|
|
145
236
|
fun rosette(r: QvpRosette): Map<String, Any?> = mapOf("decoration" to r.decoration, "surah" to r.surah, "ayah" to r.ayah, "juz" to r.juz, "hizb" to r.hizb, "nisf" to r.nisf, "rubuAlHizb" to r.rubuAlHizb, "rubuAlHizbInHizb" to r.rubuAlHizbInHizb)
|
|
146
237
|
fun sajdah(s: QvpSajdah): Map<String, Any?> = mapOf("decoration" to s.decoration, "surah" to s.surah, "ayah" to s.ayah, "signPath" to s.signPath)
|
|
147
238
|
fun match(m: QvpMatch): Map<String, Any?> = mapOf("word" to m.word, "index" to m.index, "isLooseMatch" to m.isLooseMatch, "wordKey" to m.wordKey, "text" to m.text)
|
|
239
|
+
fun passageLayoutMap(l: QvpPassageLayout, p: QvpPassage): Map<String, Any?> = mapOf("width" to l.width, "height" to l.height, "scale" to l.scale, "lineSpacing" to l.lineSpacing,
|
|
240
|
+
"printedLineSpacing" to p.lineSpacing, "isTruncated" to l.isTruncated, "ellipsis" to l.ellipsis?.let { listOf(it.left, it.top, it.right, it.bottom) },
|
|
241
|
+
"rows" to l.rows.map { mapOf("x0" to it.x0, "y0" to it.y0, "x1" to it.x1, "y1" to it.y1, "baseline" to it.baseline) },
|
|
242
|
+
"words" to l.words.map { mapOf("surah" to it.surah, "ayah" to it.ayah, "word" to it.word, "wordKey" to it.wordKey, "page" to it.page, "row" to it.row, "x0" to it.x0, "y0" to it.y0, "x1" to it.x1, "y1" to it.y1,
|
|
243
|
+
"wordX0" to it.wordX0, "wordY0" to it.wordY0, "wordX1" to it.wordX1, "wordY1" to it.wordY1) },
|
|
244
|
+
"ayahs" to l.ayahs.map { mapOf("surah" to it.surah, "ayah" to it.ayah, "x0" to it.x0, "y0" to it.y0, "x1" to it.x1, "y1" to it.y1) },
|
|
245
|
+
"texts" to p.ayahs.map { mapOf("surah" to it.surah, "ayah" to it.ayah, "text" to it.text) })
|
|
148
246
|
fun cropBounds(c: QvpCropBounds): Map<String, Any?> = mapOf("x0" to c.x0, "y0" to c.y0, "x1" to c.x1, "y1" to c.y1, "nWords" to c.nWords, "ayahMarkDecoration" to c.ayahMarkDecoration)
|
|
149
247
|
fun atlasSurah(s: QvpAtlasSurah): Map<String, Any?> = mapOf("number" to s.number, "page" to s.page, "ayahCount" to s.ayahCount, "place" to s.place, "arabic" to s.arabic, "latin" to s.latin, "english" to s.english)
|
|
150
248
|
fun atlasRubuAlHizb(r: QvpAtlasRubuAlHizb): Map<String, Any?> = mapOf("rubuAlHizb" to r.rubuAlHizb, "surah" to r.surah, "ayah" to r.ayah, "page" to r.page, "ayahKey" to r.ayahKey)
|
|
151
249
|
fun layout(l: QvpLayout): Map<String, Any?> = mapOf("scale" to l.scale, "offsetX" to l.offsetX, "offsetY" to l.offsetY, "contentW" to l.contentW, "contentH" to l.contentH, "lineSpacing" to l.lineSpacing, "fitScale" to l.fitScale, "fitX" to l.fitX, "fitY" to l.fitY, "lineDy" to l.lineDy.toList(),
|
|
152
250
|
"slots" to l.slotTop.indices.map { listOf(l.slotTop[it], l.slotBottom[it]) })
|
|
153
|
-
fun pageInfo(p: QvpPage): Map<String, Any?> = mapOf("page" to p.pageNo, "width" to p.width, "height" to p.height, "nLines" to p.nLines, "nAyahs" to p.nAyahs, "nWords" to p.nWords, "nPaths" to p.nPaths, "nDecorations" to p.nDecorations,
|
|
154
|
-
"lineSpacing" to p.lineSpacing, "forms" to
|
|
251
|
+
fun pageInfo(p: QvpPage, forms: List<Form>): Map<String, Any?> = mapOf("page" to p.pageNo, "width" to p.width, "height" to p.height, "nLines" to p.nLines, "nAyahs" to p.nAyahs, "nWords" to p.nWords, "nPaths" to p.nPaths, "nDecorations" to p.nDecorations,
|
|
252
|
+
"lineSpacing" to p.lineSpacing, "forms" to forms.map { jsName(it) })
|
|
155
253
|
fun selection(p: QvpPage): Map<String, Any?> {
|
|
156
254
|
val ws = p.selection()
|
|
157
255
|
return mapOf("words" to ws.toList(), "text" to (if (ws.isEmpty()) "" else p.text(Target.words(ws))), "citation" to (if (ws.isEmpty()) "" else p.citation(ws)),
|