/** @format */
export const componentName = "standardReadingMode"

export const component = {
    bindings: {
        data: "<",
        wordClick: "&",
    },
    controller($element) {
        const ctrl = this

        function standardInnerElem(document) {
            const doc = []
            for (let idx = 0; idx < document.tokens.length; idx++) {
                let token = document.tokens[idx]
                if (!token.tokens) {
                    doc.push(
                        `<span class="word" data-idx="${idx}">${token.attrs.head}${token.attrs.word}${token.attrs.tail}</span>`
                    )
                } else {
                    doc.push(`<div>${standardInnerElem(token.tokens)}</div>`)
                }
            }
            return `${doc.join("")}`
        }

        function standardOuterElem(data) {
            return `<div class="text-container m-md-5">${standardInnerElem(data.document)}</div>`
        }

        ctrl.$onInit = () => {
            $element[0].innerHTML = standardOuterElem(ctrl.data)

            $element[0].addEventListener("click", (e) => {
                if (e.target.dataset.idx) {
                    const idx = e.target.dataset.idx
                    const token = ctrl.data.document.tokens[idx]
                    ctrl.wordClick(["wordClick"])(token)
                }
            })
        }
    },
}

@@ -167,16 +167,39 @@
 ntroller
+: %5B%22$element%22, function
 ($elemen
@@ -1397,12 +1397,13 @@
  %7D%0A    %7D
+%5D
 ,%0A%7D%0A

fix reading mode