Skip to content

Commit 04b73db

Browse files
authored
fix(TextSpacing): use native CSS instead of JS on supported modern browsers (qiuwenbaike#1834)
* fix(TextSpacing): use native CSS instead of JS on supported modern browsers
1 parent f5bb958 commit 04b73db

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

dist/TextSpacing/TextSpacing.css

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/TextSpacing/TextSpacing.js

Lines changed: 16 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/TextSpacing/TextSpacing.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44
padding: 0 !important;
55
letter-spacing: 0.125em !important;
66
}
7+
8+
body {
9+
text-autospace: normal;
10+
text-spacing-trim: normal;
11+
}

src/TextSpacing/TextSpacing.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import './TextSpacing.less';
22
import {WRAPPER_CLASS, addSpaceToString, adjustSpacing, getLeafElements} from './modules/spacing';
3+
import {supportsTextAutospace} from './modules/supportsTextAutospace';
34

45
const run = (element: HTMLElement): void => {
56
const leaves: HTMLElement[] = getLeafElements(element);
@@ -53,4 +54,8 @@ const main = (): void => {
5354
run(output);
5455
};
5556

56-
$(main);
57+
if (supportsTextAutospace()) {
58+
console.info('[TextSpacing] text-autospace is supported natively; no need to run the script.');
59+
} else {
60+
$(main);
61+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const supportsTextAutospace = (): boolean => {
2+
if (typeof CSS !== 'undefined' && typeof CSS.supports === 'function') {
3+
if (CSS.supports('text-autospace', 'normal')) {
4+
return true;
5+
}
6+
return false;
7+
}
8+
return false;
9+
};
10+
11+
export {supportsTextAutospace};

0 commit comments

Comments
 (0)