1.1.4 • Published 2 months ago

@boosters/book-reader v1.1.4

Weekly downloads
-
License
-
Repository
-
Last release
2 months ago

@boosters/book-reader

It is library which export only 1 component - Reader. It is used for reading books.

Usage

To use this library you should install it:

npm i @boosters/book-reader

Then you can import it:

import { BookReader, Book } from '@boosters/book-reader';

And use it:

<BookReader
  book={book as Book}
  onSwitchPage={({ direction, page }) => {
    console.log(direction, page);
  }}
  onClose={() => {
    console.log('close');
  }}
  initialItemId={22}
/>

Props

NameTypeDefault valueDescription
bookBook-Book object
onBookReady(params: BookReadyParams => void-Callback which call when book content is ready
onSwitchPage(params: SwitchPageParams => void-Callback which call when user switch page
onClose(params: CloseParams => void-Callback which call when user click close button
initialItemIdnumber-paragraph id, which must be opened on opening reader
onSettingsChange(settings: SettingsChangeParams) => void-Callback which call when change reader settings
initialSettingsPartial<Settings>-Initial reader settings
fullScreenbooleantrueIf true the height of reader would be 100% of viewport
onEvent<T = Record<string, any>>(params: EventParams< T>) => void-Callback which call on events which do not affect the logic of the component. Events table
readerSizeReaderSize-Width and height params for reader
dyslexicModebooleanfalseIf true the main font switch to Dysfont exclude book content

Types and interfaces

Events for onEvent callback

NameDataDescription
look_up_shownDefinitionEvent which is dispatched when the look-up popover is opened
look_up_play_audio_clickedDefinitionEvent which is dispatched when the user clicked the listen button on the look-up popover
settings_button_clicked-Event which is dispatched when the user clicked the settings button

Book

type Book = {
  id: string
  title: string
  author: string
  chapters: Chapter[]
}

Chapter

type Chapter = {
  id: number
  uniq_id: number
  title: string
  subtitle: string
  paragraphs: Paragraph[]
}

Paragraph

type Paragraph = {
  id: number
  uniq_id: number
  type: 'text' | 'quote' | 'dialog'
  sentences: Sentence[]
}

Sentence

type Sentence = {
  id: number
  uniq_id: number
  elements: SentenceElement[]
}

SentenceElement

type SentenceElement = {
  id: number
  uniq_id: number
  text: string
  definition?: Definition
}

Definition

type Definition = {
  title: string
  description: string
  mp3?: string
}

BookReadyParams

type BookReadyParams = {
  pagesCount: number // total pages count (1 page - 1 column)
  actualPagesCount: number // pages count (1 page - 1 screen)
}

SwitchPageParams

type SwitchPageParams = {
  page: number
  direction: 'next' | 'prev'
  activeItemId: number
  progress: number
}

CloseParams

type CloseParams = {
  activeItemId: number
  progress: number
}

SettingsChangeParams

type SettingsChangeParams = {
  settings: Settings
  prevSettings: Settings
  changedParam: keyof Settings // 'theme' | 'fontFamily' | 'fontParams'
}

Link to Settings

Settings

type Settings = {
  theme: 'light' | 'dark'
  fontFamily: 'Andada' | 'Dysfont' | 'Manrope' | 'Lora' | 'Raleway'
  fontSize: number
}

EventParams

type EventParams<T = Record<string, any>> = { event: EventNames; data?: T }

Link to EventNames

ReaderSize

type ReaderSize = {
  width: number
  height: number
}
1.1.4

2 months ago

1.1.3

4 months ago

1.0.2

10 months ago

0.0.40

11 months ago

1.0.1

10 months ago

0.0.41

11 months ago

1.0.0

11 months ago

1.0.4

10 months ago

1.0.3

10 months ago

0.0.37

11 months ago

0.0.38

11 months ago

0.0.39

11 months ago

0.0.30

11 months ago

0.0.31

11 months ago

0.0.32

11 months ago

0.0.33

11 months ago

0.0.34

11 months ago

0.0.35

11 months ago

0.0.36

11 months ago

0.0.26

11 months ago

0.0.27

11 months ago

0.0.28

11 months ago

0.0.29

11 months ago

1.1.1

8 months ago

1.1.0

8 months ago

0.0.20

11 months ago

0.0.21

11 months ago

0.0.22

11 months ago

0.0.23

11 months ago

0.0.24

11 months ago

0.0.25

11 months ago

1.1.2

8 months ago

0.0.15

11 months ago

0.0.16

11 months ago

0.0.17

11 months ago

0.0.18

11 months ago

0.0.19

11 months ago

0.0.14

11 months ago

0.0.13

11 months ago

0.0.12

11 months ago

0.0.11

11 months ago

0.0.10

11 months ago

0.0.9

11 months ago

0.0.8

11 months ago

0.0.7

11 months ago

0.0.6

11 months ago

0.0.5

11 months ago

0.0.4

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago

0.0.1

11 months ago