diff --git a/.gitignore b/.gitignore index 3c3629e..55371e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +.vscode \ No newline at end of file diff --git a/components/rsvp-controls.js b/components/rsvp-controls.js new file mode 100644 index 0000000..e69de29 diff --git a/components/rsvp-reader.js b/components/rsvp-reader.js new file mode 100644 index 0000000..e69de29 diff --git a/components/rsvp-word.js b/components/rsvp-word.js new file mode 100644 index 0000000..8422e60 --- /dev/null +++ b/components/rsvp-word.js @@ -0,0 +1,51 @@ +import { pivotize } from '../src/textProcessing/pivotize.js' + +class RSVPWord extends HTMLElement { + constructor() { + super() + const shadow = this.attachShadow({ mode: 'open' }) + 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}.pivot{color:red}.prefix,.suffix{flex:1}.prefix{text-align:right}' + + word.appendChild(prefix) + word.appendChild(pivot) + word.appendChild(suffix) + shadow.appendChild(style) + shadow.appendChild(word) + + this._root = shadow + this.wordParts = { prefix, pivot, suffix } + } + + connectedCallback() { + this.updateDisplay() + } + + 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) diff --git a/index.html b/index.html index cfa20bf..7d5d04e 100644 --- a/index.html +++ b/index.html @@ -1,15 +1,47 @@ - -
- - - + + + +