Skip to content

Commit 1bf53bb

Browse files
fix(split-type): fix type option behavior and keep only selected types
1 parent 2a9a7fc commit 1bf53bb

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/index.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,29 @@ export default class SplitText {
9393
this.safeCheckBalance = 0;
9494
}
9595

96+
if (byLines && !byWords && !byChars) {
97+
this.lines.forEach((l) => {
98+
l.__words.forEach((w) => {
99+
w.insertAdjacentHTML('beforebegin', w.textContent);
100+
w.remove();
101+
});
102+
l.normalize();
103+
});
104+
this.words.length = 0;
105+
this.chars.length = 0;
106+
}
107+
96108
if (byChars) {
97-
this.words.forEach((w) => this.chars.push(...this.splitElement(w, 'char', '', false)));
109+
this.words.forEach((e) => this.chars.push(...this.splitElement(e, 'char', '', false)));
110+
if (!byWords) {
111+
this.chars.forEach((e) => {
112+
e.parentElement.insertAdjacentHTML('beforebegin', e.outerHTML);
113+
e.remove();
114+
});
115+
this.chars = toArray(element.getElementsByClassName('char'));
116+
this.words.forEach((e) => e.remove());
117+
this.words.length = 0;
118+
}
98119
}
99120
}
100121

@@ -520,7 +541,7 @@ export default class SplitText {
520541
});
521542

522543
lines.forEach((line) => {
523-
line.__words = line.getElementsByClassName('word');
544+
line.__words = toArray(line.getElementsByClassName('word'));
524545
line.__wordCount = line.__words.length;
525546
});
526547

0 commit comments

Comments
 (0)