Skip to content

Commit 77fe7b0

Browse files
committed
Replace reduceMotion logic check in typeLines with characterDelay value check. Also adds a condition to skip the await call for lines if lineDelay is not 0.
1 parent b07b9ba commit 77fe7b0

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ const loaded: Promise<unknown> = (function () {
1111
class TypingEffectElement extends HTMLElement {
1212
async connectedCallback(): Promise<void> {
1313
await loaded
14-
if (this.content)
15-
await typeLines(this.lines, this.content, this.characterDelay, this.lineDelay, this.prefersReducedMotion)
14+
if (this.content) await typeLines(this.lines, this.content, this.characterDelay, this.lineDelay)
1615
if (this.cursor) this.cursor.hidden = true
1716
this.dispatchEvent(
1817
new CustomEvent('typing:complete', {
@@ -90,11 +89,10 @@ async function typeLines(
9089
lines: string[],
9190
contentElement: HTMLElement,
9291
characterDelay: number,
93-
lineDelay: number,
94-
reduceMotion: boolean
92+
lineDelay: number
9593
): Promise<void> {
9694
for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
97-
if (reduceMotion) {
95+
if (characterDelay === 0) {
9896
contentElement.append(lines[lineIndex])
9997
} else {
10098
for (const character of lines[lineIndex].split('')) {
@@ -103,7 +101,7 @@ async function typeLines(
103101
}
104102
}
105103

106-
await wait(lineDelay)
104+
if (lineDelay !== 0) await wait(lineDelay)
107105
if (lineIndex < lines.length - 1) contentElement.append(document.createElement('br'))
108106
}
109107
}

0 commit comments

Comments
 (0)