Skip to content

Commit a61fea7

Browse files
refactor(cjk/cjt): rename handleCJK to handleCJT across files
1 parent 238cc8a commit a61fea7

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ GSAP-like text splitting class.
55
It supports:
66

77
- splitting text into lines, words, and chars
8-
- CJK locales
8+
- CJT locales
99
- nested HTML elements (with all the types of splits 😉)
1010
- text balancing
1111
- emoji
@@ -37,7 +37,7 @@ const splitTextInstance = new SplitText(el);
3737
- `noAriaLabel`: Whether to not add .sr-only content. Defaults to `false`.
3838
- `noBalance`: Whether to not balance the text using @activetheory/balance-text. Defaults to `false`.
3939
- `balanceRatio`: The ratio of the width of the element to the width of the parent. Defaults to `1`.
40-
- `handleCJK`: Whether to handle CJK characters. Defaults to `false`.
40+
- `handleCJT`: Whether to handle CJT characters. Defaults to `false`.
4141

4242
## Properties
4343

@@ -59,7 +59,7 @@ To run the demo, run `npm run dev`.
5959

6060
## Notes
6161

62-
### CJK locales
62+
### CJT locales
6363

64-
The `handleCJK` option will leverage `​` to split the text properly.
64+
The `handleCJT` option will leverage `​` to split the text properly.
6565
We suggest to have a look at https://github.com/google/budoux/ for more information about how to place `​` in your text.

demo/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ <h1>Split Text</h1>
3535
<label for="input-no-balance">No balance<br /><small>turn of the balance-text library</small></label>
3636
</div>
3737
<div>
38-
<input type="checkbox" id="input-handle-cjk" />
39-
<label for="input-handle-cjk">Handle CJK</label>
38+
<input type="checkbox" id="input-handle-cjt" />
39+
<label for="input-handle-cjt">Handle CJT</label>
4040
</div>
4141
</fieldset>
4242
<fieldset>

demo/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ document.addEventListener('DOMContentLoaded', () => {
1414
const typeChars = document.getElementById('input-type-chars');
1515
const noAriaLabel = document.getElementById('input-no-aria-label');
1616
const noBalance = document.getElementById('input-no-balance');
17-
const handleCJK = document.getElementById('input-handle-cjk');
17+
const handleCJT = document.getElementById('input-handle-cjt');
1818
const cssBalance = document.getElementById('input-balance');
1919
// Get font size input
2020
const fontSize = document.getElementById('input-font-size');
@@ -32,7 +32,7 @@ document.addEventListener('DOMContentLoaded', () => {
3232
type: types.join(','),
3333
noAriaLabel: noAriaLabel.checked,
3434
noBalance: noBalance.checked,
35-
handleCJK: handleCJK.checked,
35+
handleCJT: handleCJT.checked,
3636
};
3737
};
3838

@@ -67,7 +67,7 @@ document.addEventListener('DOMContentLoaded', () => {
6767
// Event listeners
6868
inputText.addEventListener('input', updateSplit);
6969
fontSize.addEventListener('input', updateFontSize);
70-
[typeLines, typeWords, typeChars, noAriaLabel, noBalance, handleCJK, cssBalance].forEach((checkbox) => {
70+
[typeLines, typeWords, typeChars, noAriaLabel, noBalance, handleCJT, cssBalance].forEach((checkbox) => {
7171
checkbox.addEventListener('change', updateSplit);
7272
});
7373

src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export type SplitTextOptions = {
55
noAriaLabel?: boolean;
66
noBalance?: boolean;
77
balanceRatio?: number;
8-
handleCJK?: boolean;
8+
handleCJT?: boolean;
99
};
1010

1111
export default class SplitText {

src/index.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class SplitText {
3737
noBalance: false,
3838
balanceRatio: 1,
3939
minLines: 1,
40-
handleCJK: false,
40+
handleCJT: false,
4141
}
4242
) {
4343
this.elements = toArray(element);
@@ -47,7 +47,7 @@ export default class SplitText {
4747
this.options.noAriaLabel = typeof this.options.noAriaLabel === 'boolean' ? this.options.noAriaLabel : false;
4848
this.options.noBalance = typeof this.options.noBalance === 'boolean' ? this.options.noBalance : false;
4949
this.options.minLines = typeof this.options.minLines === 'number' ? this.options.minLines : 1;
50-
this.options.handleCJK = typeof this.options.handleCJK === 'boolean' ? this.options.handleCJK : false;
50+
this.options.handleCJT = typeof this.options.handleCJT === 'boolean' ? this.options.handleCJT : false;
5151
this.options.type = typeof this.options.type === 'string' ? this.options.type : 'lines';
5252
this.split();
5353
}
@@ -269,14 +269,14 @@ export default class SplitText {
269269
replaceWords(element, notByChars) {
270270
Array.from(element.getElementsByClassName('word')).forEach((el, i) => {
271271
el.replaceWith(this.words[i]);
272-
if (el.__isCJK && notByChars) {
272+
if (el.__isCJT && notByChars) {
273273
this.words[i].innerHTML = this.words[i].textContent;
274274
}
275275
});
276276
}
277277

278-
// CJK locales + Thai
279-
isCJKChar(char) {
278+
// CJT locales + Thai
279+
isCJTChar(char) {
280280
return /[\u4E00-\u9FFF\u3400-\u4DBF\u3040-\u309F\u30A0-\u30FF\uAC00-\uD7AF\u0E00-\u0E7F]/.test(char);
281281
}
282282

@@ -292,7 +292,7 @@ export default class SplitText {
292292
allElements.push(document.createTextNode(wholeText[0]));
293293
}
294294

295-
if (this.options.handleCJK && key === 'word') {
295+
if (this.options.handleCJT && key === 'word') {
296296
// Split text into words first
297297
const words = contents.split(/(\s+)/).filter(Boolean);
298298

@@ -307,14 +307,14 @@ export default class SplitText {
307307

308308
// Process each character in the word
309309
let currentWord = '';
310-
let isCJKMode = false;
310+
let isCJTMode = false;
311311

312312
for (let j = 0; j < word.length; j++) {
313313
const char = word[j];
314-
const isCurrentCharCJK = this.isCJKChar(char);
314+
const isCurrentCharCJT = this.isCJTChar(char);
315315

316316
// Mode switch or end of word
317-
if (isCurrentCharCJK !== isCJKMode || j === word.length - 1) {
317+
if (isCurrentCharCJT !== isCJTMode || j === word.length - 1) {
318318
// Add the current character to the word
319319
if (j === word.length - 1) {
320320
currentWord += char;
@@ -326,23 +326,23 @@ export default class SplitText {
326326
elements.push(splitEl);
327327
allElements.push(splitEl);
328328

329-
// If it's CJK, split into individual characters
330-
if (isCJKMode) {
331-
splitEl.__isCJK = true;
329+
// If it's CJT, split into individual characters
330+
if (isCJTMode) {
331+
splitEl.__isCJT = true;
332332
this.chars.push(...this.splitElement(splitEl, 'char', '', false));
333333
}
334334
}
335335

336336
// Reset for next segment
337337
currentWord = j === word.length - 1 ? '' : char;
338-
isCJKMode = isCurrentCharCJK;
338+
isCJTMode = isCurrentCharCJT;
339339
} else {
340340
currentWord += char;
341341
}
342342
}
343343
}
344344
} else {
345-
// Regular handling for non-CJK text or when handleCJK is false
345+
// Regular handling for non-CJT text or when handleCJT is false
346346
if (key === 'char') {
347347
// Use Array.from to properly split Unicode characters including emojis
348348
const chars = Array.from(contents);

0 commit comments

Comments
 (0)