Remove old files

This commit is contained in:
Alfred Melch 2019-12-14 14:10:43 +01:00
parent 46f3d1f095
commit c3f5fdcd18
5 changed files with 0 additions and 304 deletions

View File

@ -1,25 +0,0 @@
import { Chapter } from './Chapter.js'
import { Player } from './Player.js'
export class Book {
constructor() {
this.chapters = [new Chapter('')]
this.curIdx = 0
this.player = new Player()
}
get currentChapter() {
return this.chapters(curIdx)
}
addChapter(chapter) {
this.chapters.push(chapter)
}
removeChapter(chapter) {
this.chapters.filter(el => el !== chapter)
if (this.curIdx > 0) {
this.curIdx--
}
}
}

View File

@ -1,139 +0,0 @@
import { parseText } from './textProcessing/parseText.js'
export class Chapter {
constructor(text, maxLength = -1) {
this._originalText = text
this._maxLength = maxLength
this.initSegments()
}
initSegments() {
let { segments, words, sentences } = parseText(this._text, this._maxLength)
this.segments = segments
this.words = words
this.sentences = sentences
this.resetIndex()
}
resetIndex() {
this.currentIdx = 0
}
setText(text) {
this._originalText = text
this.initSegments()
}
setMaxLength(maxLength) {
this._maxLength = maxLength
this.initSegments()
}
get currentSegment() {
return this.segments[this.currentIdx]
}
get metainfo() {
return {
segmentCount: this.segments.length,
wordsCount: this.words.length,
sentenceCount: this.sentences.length,
currentSegment: currentIdx + 1,
currentWord: -1,
currentSentence: -1
}
}
next() {
if (!this.hasNext()) return null
this.currentIdx += 1
return this.currentSegment
}
prev() {
if (!this.hasPrev()) return null
this.currentIdx -= 1
return this.currentSegment
}
nextWord() {
if (!this.hasNextWord()) return null
this.currentIdx = getNextBiggerNumber(this.currentIdx, this.words)
return this.currentSegment
}
prevWord() {
if (!this.hasPrevWord()) return null
this.currentIdx = getNextSmallerNumber(this.currentIdx, this.words)
return this.currentSegment
}
nextSentence() {
if (!this.hasNextSentence()) return null
this.currentIdx = getNextBiggerNumber(this.currentIdx, this.sentences)
return this.currentSegment
}
prevSentence() {
if (!this.hasPrevSentence()) return null
this.currentIdx = getNextSmallerNumber(this.currentIdx, this.sentences)
return this.currentSegment
}
hasNext() {
return this.currentIdx < this.segments.length - 1
}
hasPrev() {
return this.currentIdx > 0
}
hasNextWord() {
return this.currentIdx < lastEntry(this.words)
}
hasPrevWord() {
return this.currentIdx > this.words[0]
}
hasNextSentence() {
return this.currentIdx < lastEntry(this.sentences)
}
hasPrevSentence() {
return this.currentIdx > this.sentences[0]
}
}
/**
* Returns the next bigger number from a sorted Array of numbers.
* Returns null if num is the biggest number
* @param {Number} idx
* @param {Array<Number>} sortedArray
*/
function getNextBiggerNumber(num, sortedArray) {
for (let currentNumber of sortedArray) {
if (currentNumber > num) return currentNumber
}
return null
}
/**
* Returns the next smaller number from a sorted Array of numbers.
* Returns null if num is the smallest number
* @param {Number} idx
* @param {Array<Number>} sortedArray
*/
function getNextSmallerNumber(num, sortedArray) {
let reversedArray = [...sortedArray].reverse()
for (let currentNumber of reversedArray) {
if (currentNumber < num) return currentNumber
}
return null
}
function lastEntry(arr) {
return arr[arr.length - 1]
}
export const _privates = { getNextBiggerNumber }

View File

@ -1,45 +0,0 @@
export class Player {
constructor(interval = 200) {
this.intervalHandle = null
this.interval = interval
this.subscribers = {}
}
get playing() {
return this.intervalHandle !== null
}
start() {
clearInterval(this.intervalHandle)
this.intervalHandle = setInterval(this.tick.bind(this), this.interval)
}
stop() {
clearInterval(this.intervalHandle)
this.intervalHandle = null
}
toggle() {
if (this.playing) this.stop()
else this.start()
}
updateInterval(interval) {
this.interval = interval
if (this.intervalHandle) this.start()
}
tick() {
for (let callback of Object.values(this.subscribers)) {
callback()
}
}
subscribe(name, callback) {
this.subscribers[name] = callback
}
unsubscribe(name) {
delete subscribers[name]
}
}

View File

@ -1,70 +0,0 @@
import { RSVPPlayer } from './RSVPPlayer.js'
const initialOptions = {
maxLength: 10,
autoPlayNextChapter: false,
wordsPerMinute: 200,
pivotMethod: 'default',
pauseOnPunctuation: true
}
export class RSVPController {
constructor(options = {}) {
this.options = initialOptions
this.setOptions(options)
this.rsvpPlayer = new RSVPPlayer()
this.rsvpPlayer.onTick = this.onChange
this.applyOptions()
}
setOptions(options) {
this.options = { ...this.options, ...options }
}
applyOptions() {
let { options } = this
let { chapter, player } = this.rsvpPlayer
chapter.setMaxLength = options.maxLength
player.updateInterval(1000 / options.wordsPerMinute)
}
updateOptions(options) {
this.setOptions(options)
this.applyOptions()
this.onChange()
}
processAction(action, payload) {
let { chapter, player } = this.rsvpPlayer
switch (action) {
case 'prevSentence':
chapter.prevSentence()
break
case 'nextSentence':
chapter.nextSentence()
break
case 'prevWord':
chapter.prevWord()
break
case 'nextWord':
chapter.nextWord()
break
case 'playpause':
player.toggle()
break
case 'stop':
player.stop()
chapter.reset()
break
case 'load':
chapter = new Chapter(payload, 10)
}
this.onChange()
}
onChange() {
console.warn('RSVPController: onChange not set')
}
}

View File

@ -1,25 +0,0 @@
import { Player } from './Player.js'
import { Book } from './Book.js'
import { Chapter } from './Chapter.js'
export class RSVPPlayer {
constructor(maxLength) {
this.chapter = new Chapter(maxLength)
this.player = new Player()
this.player.subscribe('main', this.tick.bind(this))
}
tick() {
if (!this.chapter.hasNext()) {
this.player.stop()
} else {
this.chapter.next()
}
this.onTick()
}
onTick() {
console.warn('RSVPPlayer: onTick not set')
}
}