misraj-mushaf-renderer 1.1.21 → 1.2.1
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 +76 -45
- package/dist/classnames.d.ts +6 -16
- package/dist/components/MushafReader/Provider.d.ts +8 -0
- package/dist/components/MushafReader/ReadingView/Line.d.ts +1 -1
- package/dist/components/MushafReader/ReadingView/Page.d.ts +1 -3
- package/dist/components/MushafReader/ReadingView/page-metadata/PageMetaDataContainer.d.ts +2 -1
- package/dist/components/MushafReader/contexts/MushafPage/MushafPage.types.d.ts +0 -6
- package/dist/components/MushafReader/contexts/MushafPage/MushafPageProvider.d.ts +4 -1
- package/dist/components/MushafReader/contexts/Theme/ThemeProvider.d.ts +3 -0
- package/dist/components/MushafReader/contexts/Theme/type.d.ts +25 -0
- package/dist/components/MushafReader/index.d.ts +1 -1
- package/dist/components/chapters/ChapterHeader/index.d.ts +0 -2
- package/dist/components/chapters/ChapterIcon/ChapterIconContainer.d.ts +0 -2
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.es.js +1426 -1383
- package/dist/index.es.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,11 +38,11 @@ Make sure to import package styles file which includes css styles and fonts asse
|
|
|
38
38
|
import 'misraj-mushaf-renderer/dist/styles';
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
The core of the library is the `
|
|
41
|
+
The core of the library is the `MushafReaderProvider` and the `Mushaf` component.
|
|
42
42
|
|
|
43
|
-
### 1. `
|
|
43
|
+
### 1. `MushafReaderProvider`
|
|
44
44
|
|
|
45
|
-
The `
|
|
45
|
+
The `MushafReaderProvider` is a React context provider that fetches and manages the state for a specific Mushaf page. You need to wrap any component that will render Mushaf text with it.
|
|
46
46
|
|
|
47
47
|
**Props:**
|
|
48
48
|
|
|
@@ -52,20 +52,20 @@ The `MushafPageProvider` is a React context provider that fetches and manages th
|
|
|
52
52
|
- `initialFontScale` (number, optional): The initial font scale. Defaults to `3`.
|
|
53
53
|
- `hasBorder` (boolean, optional): Whether to display the page border. Defaults to `true`.
|
|
54
54
|
- `initialIsTwoPagesView` (boolean, optional): The initial state for two-page view. Defaults to `false`.
|
|
55
|
+
- `themeProps` (object, optional): An object to override default theme styles. See the "Styling and Customization" section.
|
|
56
|
+
- `styleOverride` (object, optional): An object to provide custom CSS classes to components. See the "Styling and Customization" section.
|
|
55
57
|
|
|
56
58
|
### 2. `useMushafContext` Hook
|
|
57
59
|
|
|
58
|
-
This hook provides access to the state and actions of the `
|
|
60
|
+
This hook provides access to the state and actions of the `MushafReaderProvider`. It should be used by components that are children of `MushafReaderProvider`.
|
|
59
61
|
|
|
60
62
|
**State:**
|
|
61
63
|
|
|
62
64
|
- `fontScale` (number): The current font scale.
|
|
63
65
|
- `selectedVerse` (Ayah | null): The currently selected verse.
|
|
64
|
-
- `currentSurah` (Surah | null): The current surah being displayed.
|
|
65
66
|
- `ayat` (MushafPageDataType | null): The raw data for the current page.
|
|
66
67
|
- `nextPageAyat` (MushafPageDataType | null): The data for the next page, used in two-page view.
|
|
67
68
|
- `error` (Error | null): Any error that occurred while fetching data.
|
|
68
|
-
- `loading` (boolean): A boolean indicating if the page data is loading.
|
|
69
69
|
- `pageNumber` (number): The current page number.
|
|
70
70
|
- `dataId` (DataId): The current narration identifier.
|
|
71
71
|
- `isTwoPagesView` (boolean): Whether the two-page view is currently active.
|
|
@@ -75,34 +75,23 @@ This hook provides access to the state and actions of the `MushafPageProvider`.
|
|
|
75
75
|
- `increaseFontScale()`: Increases the font scale.
|
|
76
76
|
- `decreaseFontScale()`: Decreases the font scale.
|
|
77
77
|
- `setSelectedVerse(verse: Ayah | null)`: Sets the selected verse.
|
|
78
|
-
- `setCurrentSurah(surah: Surah | null)`: Sets the current surah.
|
|
79
78
|
|
|
80
79
|
**Example:**
|
|
81
80
|
|
|
82
81
|
```tsx
|
|
83
|
-
import {
|
|
84
|
-
MushafPageProvider,
|
|
85
|
-
useMushafContext,
|
|
86
|
-
} from '@src/components/MushafReader/contexts/MushafPage/MushafPageProvider';
|
|
87
|
-
import Mushaf from '@src/components/MushafReader';
|
|
82
|
+
import { MushafReaderProvider, useMushafContext, Mushaf } from 'misraj-mushaf-renderer';
|
|
88
83
|
|
|
89
84
|
function App() {
|
|
90
85
|
return (
|
|
91
|
-
<
|
|
86
|
+
<MushafReaderProvider dataId="quran-hafs" pageNumber={1} initialIsTwoPagesView={true}>
|
|
92
87
|
<MushafReader />
|
|
93
|
-
</
|
|
88
|
+
</MushafReaderProvider>
|
|
94
89
|
);
|
|
95
90
|
}
|
|
96
91
|
|
|
97
92
|
function MushafReader() {
|
|
98
|
-
const {
|
|
99
|
-
|
|
100
|
-
currentSurah,
|
|
101
|
-
fontScale,
|
|
102
|
-
increaseFontScale,
|
|
103
|
-
decreaseFontScale,
|
|
104
|
-
setSelectedVerse,
|
|
105
|
-
} = useMushafContext();
|
|
93
|
+
const { pageNumber, fontScale, increaseFontScale, decreaseFontScale, setSelectedVerse } =
|
|
94
|
+
useMushafContext();
|
|
106
95
|
|
|
107
96
|
const handleWordClick = (word) => {
|
|
108
97
|
// select the verse the word belongs to
|
|
@@ -116,9 +105,7 @@ function MushafReader() {
|
|
|
116
105
|
return (
|
|
117
106
|
<div>
|
|
118
107
|
<header>
|
|
119
|
-
<h1>
|
|
120
|
-
Page {pageNumber} - Surah {currentSurah?.name}
|
|
121
|
-
</h1>
|
|
108
|
+
<h1>Page {pageNumber}</h1>
|
|
122
109
|
<div>
|
|
123
110
|
<button onClick={decreaseFontScale}>A-</button>
|
|
124
111
|
<span>Font size: {fontScale}</span>
|
|
@@ -133,15 +120,14 @@ function MushafReader() {
|
|
|
133
120
|
|
|
134
121
|
### 3. `Mushaf` Component
|
|
135
122
|
|
|
136
|
-
This component consumes the data fetched by `
|
|
123
|
+
This component consumes the data fetched by `MushafReaderProvider` and renders the actual Mushaf page(s).
|
|
137
124
|
|
|
138
|
-
It accepts several optional props to handle user interactions
|
|
125
|
+
It accepts several optional props to handle user interactions.
|
|
139
126
|
|
|
140
127
|
**Props:**
|
|
141
128
|
|
|
142
129
|
- `onWordClick(word: Word)`: A callback function that triggers when a user clicks on a specific word. The `word` object contains detailed information about the word, including its location, text, and verse key.
|
|
143
130
|
- `onWordHover(word: Word)`: A callback function that triggers when a user hovers over a word.
|
|
144
|
-
- `styleOverride`: An object to override default styles. See the "Overriding Styles" section for more details.
|
|
145
131
|
|
|
146
132
|
## How It Works: The Rendering Process
|
|
147
133
|
|
|
@@ -153,7 +139,7 @@ Rendering a Mushaf page is a complex process that this library simplifies into a
|
|
|
153
139
|
|
|
154
140
|
3. **`MushafWord.tsx`** (`@src/components/dls/MushafWord/MushafWord.tsx`): This is the most granular component, responsible for rendering a single Mushaf word. It attaches the `onClick` and `onMouseEnter` event listeners and applies the specific font-family for the current narration via CSS classes defined in `MushafWord.module.scss`.
|
|
155
141
|
|
|
156
|
-
## Styling
|
|
142
|
+
## Styling and Customization
|
|
157
143
|
|
|
158
144
|
The library's styling is managed through SCSS, offering a high degree of customization.
|
|
159
145
|
|
|
@@ -162,33 +148,78 @@ The library's styling is managed through SCSS, offering a high degree of customi
|
|
|
162
148
|
- **Fonts**: The `@font-face` declarations for all supported narrations are located in `@src/styles/fonts.scss`.
|
|
163
149
|
- **Responsiveness**: Breakpoints for various screen sizes are defined in `@src/styles/_breakpoints.scss` to ensure the layout is responsive.
|
|
164
150
|
|
|
165
|
-
|
|
151
|
+
The library offers two primary ways to customize the appearance of the Mushaf renderer: `themeProps` for global theme adjustments and `styleOverride` for fine-grained component-level style changes. Both are passed as props to the `MushafReaderProvider`.
|
|
166
152
|
|
|
167
|
-
|
|
153
|
+
### 1. Theming with `themeProps`
|
|
154
|
+
|
|
155
|
+
The `themeProps` object allows you to easily change the overall theme by setting global CSS variables at runtime.
|
|
168
156
|
|
|
169
157
|
**Available Options:**
|
|
170
158
|
|
|
171
|
-
- `
|
|
172
|
-
- `
|
|
159
|
+
- `borderColor` ('blue' | 'green' | 'sepia'): Sets the color for the page borders and the default word highlight color.
|
|
160
|
+
- `wordHighlightColor` (string): Overrides the default highlight color for words when they are hovered or selected. Accepts any valid CSS color value.
|
|
161
|
+
- `chapterHeaderFontSize` (string): The font size for the chapter headers (surah names). Accepts any valid CSS font-size value.
|
|
173
162
|
- `primaryFontColor` (string): The primary color of the Quranic text.
|
|
174
|
-
- `borderColor`: ('blue' | 'green' | 'sepia') Supported border colors;
|
|
175
163
|
|
|
176
164
|
**Example:**
|
|
177
165
|
|
|
178
166
|
```tsx
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
167
|
+
const themeProps = {
|
|
168
|
+
borderColor: 'sepia',
|
|
169
|
+
wordHighlightColor: '#D4AF37', // Gold highlight
|
|
170
|
+
chapterHeaderFontSize: '2.5rem',
|
|
171
|
+
primaryFontColor: '#333333', // Dark gray text
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
<MushafReaderProvider dataId="quran-hafs" pageNumber={1} themeProps={themeProps}>
|
|
175
|
+
<Mushaf />
|
|
176
|
+
</MushafReaderProvider>;
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### 2. Component-level styling with `styleOverride`
|
|
180
|
+
|
|
181
|
+
For more specific, dynamic, or one-off styling changes, the `styleOverride` prop allows you to apply a `React.CSSProperties` object directly to the library's internal components.
|
|
182
|
+
|
|
183
|
+
The `styleOverride` object follows this structure:
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
{
|
|
187
|
+
[ComponentName]?: {
|
|
188
|
+
[StyleKey]?: React.CSSProperties; // A CSS style object
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
- `ComponentName` corresponds to the components you want to style (e.g., `Page`, `MushafWord`, `MushafReader`).
|
|
194
|
+
- `StyleKey` corresponds to a stylable element within that component (e.g., `container`, `highlighted`, `twoPagesRow`).
|
|
186
195
|
|
|
196
|
+
You can find all available `ComponentName` and `StyleKey` values in the exported `classnames` object.
|
|
197
|
+
|
|
198
|
+
**Example:**
|
|
199
|
+
|
|
200
|
+
Let's say you want to remove the gap between the two pages in the two-page view. You can do this by passing a style object to the `twoPagesRow` style key of the `MushafReader` component.
|
|
201
|
+
|
|
202
|
+
```tsx
|
|
203
|
+
import { Mushaf, MushafReaderProvider } from 'misraj-mushaf-renderer';
|
|
204
|
+
|
|
205
|
+
const styleOverride = {
|
|
206
|
+
MushafReader: {
|
|
207
|
+
twoPagesRow: {
|
|
208
|
+
gap: 0,
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
function App() {
|
|
187
214
|
return (
|
|
188
|
-
<
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
215
|
+
<MushafReaderProvider
|
|
216
|
+
dataId="quran-hafs"
|
|
217
|
+
pageNumber={1}
|
|
218
|
+
styleOverride={styleOverride}
|
|
219
|
+
initialIsTwoPagesView={true}
|
|
220
|
+
>
|
|
221
|
+
<Mushaf />
|
|
222
|
+
</MushafReaderProvider>
|
|
192
223
|
);
|
|
193
224
|
}
|
|
194
225
|
```
|
package/dist/classnames.d.ts
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
declare const classnames: {
|
|
2
|
-
ChapterIconContainer:
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
filled: string;
|
|
9
|
-
highlightOnHover: string;
|
|
10
|
-
highlighted: string;
|
|
11
|
-
};
|
|
12
|
-
ReadingView: {
|
|
13
|
-
container: string;
|
|
14
|
-
};
|
|
15
|
-
VerseText: {
|
|
16
|
-
highlighted: string;
|
|
17
|
-
};
|
|
2
|
+
ChapterIconContainer: readonly ["iconContainer"];
|
|
3
|
+
MushafWord: readonly ["colored", "filled", "highlightOnHover", "highlighted"];
|
|
4
|
+
ReadingView: readonly ["container"];
|
|
5
|
+
VerseText: readonly ["highlighted"];
|
|
6
|
+
MushafReader: readonly ["twoPagesRow"];
|
|
7
|
+
Page: readonly ["container", "border", "blueBorder", "sepiaBorder", "bottomBorder", "blueBottomBorder", "sepiaBottomBorder", "mobileCenterText", "firstTwoPagesBorder", "blueFirstTwoPagesBorder", "sepiaFirstTwoPagesBorder", "pageNumberContainer", "pageNumber", "surah", "juz"];
|
|
18
8
|
};
|
|
19
9
|
export default classnames;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MushafPageProviderProps } from './contexts/MushafPage/MushafPageProvider';
|
|
2
|
+
import { ThemeProviderProps } from './contexts/Theme/type';
|
|
3
|
+
type MushafReaderProviderProps = MushafPageProviderProps & {
|
|
4
|
+
themeProps?: ThemeProviderProps['themeProps'];
|
|
5
|
+
styleOverride?: ThemeProviderProps['styleOverride'];
|
|
6
|
+
};
|
|
7
|
+
declare const MushafReaderProvider: ({ children, themeProps, styleOverride, ...props }: MushafReaderProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export default MushafReaderProvider;
|
|
@@ -10,5 +10,5 @@ type LineProps = {
|
|
|
10
10
|
onWordHover?: (word: Word, event: React.MouseEvent<HTMLElement>) => void;
|
|
11
11
|
borderColor?: BorderColor;
|
|
12
12
|
};
|
|
13
|
-
declare const _default: import('react').MemoExoticComponent<({ lineKey, words, isBigTextLayout, pageIndex, lineIndex, onWordClick, onWordHover,
|
|
13
|
+
declare const _default: import('react').MemoExoticComponent<({ lineKey, words, isBigTextLayout, pageIndex, lineIndex, onWordClick, onWordHover, }: LineProps) => import("react/jsx-runtime").JSX.Element>;
|
|
14
14
|
export default _default;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { default as Word } from '../../../types/Word';
|
|
3
3
|
import { Ayah } from '../../../types/verses';
|
|
4
|
-
import { BorderColor } from '../../../types/border-color';
|
|
5
4
|
type PageProps = {
|
|
6
5
|
verses: Ayah[];
|
|
7
6
|
pageNumber: number;
|
|
8
7
|
pageIndex: number;
|
|
9
8
|
onWordClick?: (word: Word, event: React.MouseEvent<HTMLElement>) => void;
|
|
10
9
|
onWordHover?: (word: Word, event: React.MouseEvent<HTMLElement>) => void;
|
|
11
|
-
borderColor?: BorderColor;
|
|
12
10
|
};
|
|
13
|
-
declare const Page: ({ verses, pageNumber, pageIndex, onWordClick, onWordHover
|
|
11
|
+
declare const Page: ({ verses, pageNumber, pageIndex, onWordClick, onWordHover }: PageProps) => import("react/jsx-runtime").JSX.Element;
|
|
14
12
|
export default Page;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { BorderColor } from '../../../../types/border-color';
|
|
3
|
-
declare const PageMetaDataContainer: ({ className, children, borderColor, }: {
|
|
3
|
+
declare const PageMetaDataContainer: ({ className, children, borderColor, style, }: {
|
|
4
4
|
className?: string;
|
|
5
5
|
children: React.ReactNode;
|
|
6
6
|
borderColor?: BorderColor;
|
|
7
|
+
style?: React.CSSProperties;
|
|
7
8
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
8
9
|
export default PageMetaDataContainer;
|
|
@@ -6,11 +6,5 @@ export type DataId = NarrationId | ReciterId;
|
|
|
6
6
|
export interface MushafPageProps {
|
|
7
7
|
onWordClick?: (word: Word, event: React.MouseEvent<HTMLElement>) => void;
|
|
8
8
|
onWordHover?: (word: Word, event: React.MouseEvent<HTMLElement>) => void;
|
|
9
|
-
styleOverride?: {
|
|
10
|
-
borderColor?: 'blue' | 'green' | 'sepia';
|
|
11
|
-
wordHighlightColor?: string;
|
|
12
|
-
chapterHeaderFontSize?: string;
|
|
13
|
-
primaryFontColor?: string;
|
|
14
|
-
};
|
|
15
9
|
}
|
|
16
10
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { Ayah, IVersesListDto } from '../../../../types/verses';
|
|
3
3
|
import { DataId } from './MushafPage.types';
|
|
4
|
+
import { ThemeProviderProps } from '../Theme/type';
|
|
4
5
|
/** ---------- Types ---------- */
|
|
5
6
|
type MushafPageState = {
|
|
6
7
|
fontScale: number;
|
|
@@ -19,13 +20,15 @@ type MushafPageActions = {
|
|
|
19
20
|
setSelectedVerse: React.Dispatch<React.SetStateAction<Ayah | null>>;
|
|
20
21
|
refresh: () => void;
|
|
21
22
|
};
|
|
22
|
-
type MushafPageProviderProps = {
|
|
23
|
+
export type MushafPageProviderProps = {
|
|
23
24
|
children: React.ReactNode;
|
|
24
25
|
dataId: DataId;
|
|
25
26
|
pageNumber: number;
|
|
26
27
|
initialFontScale?: number;
|
|
27
28
|
hasBorder?: boolean;
|
|
28
29
|
initialIsTwoPagesView?: boolean;
|
|
30
|
+
themeProps?: ThemeProviderProps['themeProps'];
|
|
31
|
+
styleOverride?: ThemeProviderProps['styleOverride'];
|
|
29
32
|
};
|
|
30
33
|
export declare const MushafPageProvider: ({ children, dataId, pageNumber, initialFontScale, hasBorder, initialIsTwoPagesView, }: MushafPageProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
31
34
|
export type MushafContextStateTypes = MushafPageState & MushafPageActions;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { default as classnames } from '../../../../classnames';
|
|
3
|
+
import { BorderColor } from '../../../../types/border-color';
|
|
4
|
+
type ThemeProps = {
|
|
5
|
+
borderColor?: BorderColor;
|
|
6
|
+
wordHighlightColor?: string;
|
|
7
|
+
chapterHeaderFontSize?: string;
|
|
8
|
+
primaryFontColor?: string;
|
|
9
|
+
};
|
|
10
|
+
type ClassnameGroups = typeof classnames;
|
|
11
|
+
type GroupName = keyof ClassnameGroups;
|
|
12
|
+
type GroupKey<K extends GroupName> = ClassnameGroups[K][number];
|
|
13
|
+
type StyleOverride = {
|
|
14
|
+
[K in GroupName]?: Partial<Record<GroupKey<K>, React.CSSProperties>>;
|
|
15
|
+
};
|
|
16
|
+
export type ThemeState = {
|
|
17
|
+
themeProps: ThemeProps;
|
|
18
|
+
styleOverride: StyleOverride;
|
|
19
|
+
};
|
|
20
|
+
export type ThemeProviderProps = {
|
|
21
|
+
children: React.ReactNode;
|
|
22
|
+
themeProps?: ThemeProps;
|
|
23
|
+
styleOverride?: StyleOverride;
|
|
24
|
+
};
|
|
25
|
+
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { MushafPageProps } from './contexts/MushafPage/MushafPage.types';
|
|
2
|
-
declare const Mushaf: ({ onWordClick, onWordHover
|
|
2
|
+
declare const Mushaf: ({ onWordClick, onWordHover }: MushafPageProps) => import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
export default Mushaf;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
-
import { BorderColor } from '../../../types/border-color';
|
|
3
2
|
interface Props {
|
|
4
3
|
chapterId: string;
|
|
5
4
|
pageNumber: number;
|
|
6
|
-
borderColor?: BorderColor;
|
|
7
5
|
}
|
|
8
6
|
declare const ChapterHeader: React.FC<Props>;
|
|
9
7
|
export default ChapterHeader;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
-
import { BorderColor } from '../../../types/border-color';
|
|
3
2
|
interface Props {
|
|
4
3
|
chapterId: string;
|
|
5
4
|
hasSurahPrefix?: boolean;
|
|
6
|
-
borderColor?: BorderColor;
|
|
7
5
|
}
|
|
8
6
|
declare const IconContainer: React.FC<Props>;
|
|
9
7
|
export default IconContainer;
|