Spaces:
Running
Running
File size: 832 Bytes
2d2e027 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
class Markup {
private static scrollToBottom(opts: { animate?: boolean } = {}) {
App.messagesRoot.scrollTop = App.messagesRoot.scrollHeight;
}
private static messageMarkup(m: Message): string {
const incomingStr = m.incoming ? 'incoming' : 'outgoing';
return `<div class="message ${incomingStr}">
<div class="message-inner">${Utils.escape(m.content)}</div>
</div>`;
}
static append(m: Message) {
const s = this.messageMarkup(m);
App.messagesRoot.insertAdjacentHTML('beforeend', s);
this.scrollToBottom();
}
/**
* Bucketize a float into a level
* according to a set of thresholds.
*/
static attentionThreshold(att: number): number {
const thresholds = [2, 4.5, 10, 30];
for (const [i, x] of thresholds.entries()) {
if (x > att) {
return i;
}
}
return thresholds.length;
}
}
|