You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.6 KiB
JavaScript

5 years ago
import { pivotize } from '../src/textProcessing/pivotize.js'
5 years ago
import { RSVPComponent } from './rsvp-component.js'
5 years ago
5 years ago
class RSVPWord extends RSVPComponent {
5 years ago
constructor() {
super()
const style = document.createElement('style')
const word = document.createElement('div')
const prefix = document.createElement('span')
const pivot = document.createElement('span')
const suffix = document.createElement('span')
word.setAttribute('class', 'word')
prefix.setAttribute('class', 'prefix')
pivot.setAttribute('class', 'pivot')
suffix.setAttribute('class', 'suffix')
style.textContent =
'.word{display:flex; font-size: 2.4em;}.pivot{color:red}.prefix{flex:1}.suffix{flex:1}.prefix{text-align:right}'
5 years ago
word.appendChild(prefix)
word.appendChild(pivot)
word.appendChild(suffix)
5 years ago
this._root.appendChild(style)
this._root.appendChild(word)
5 years ago
this.wordParts = { prefix, pivot, suffix }
}
5 years ago
update({ chapter }) {
const [prefix, pivot, suffix] = pivotize(chapter.currentSegment)
this.wordParts.prefix.innerText = prefix
this.wordParts.pivot.innerText = pivot
this.wordParts.suffix.innerText = suffix
5 years ago
}
static get observedAttributes() {
return ['word']
}
attributeChangedCallback() {
this.updateDisplay()
}
updateDisplay() {
const [prefix, pivot, suffix] = pivotize(this.getAttribute('word') || '')
this.wordParts.prefix.innerText = prefix
this.wordParts.pivot.innerText = pivot
this.wordParts.suffix.innerText = suffix
}
}
window.customElements.define('rsvp-word', RSVPWord)