Skip to content

Commit 8311b3f

Browse files
committed
refactor: switch to browser-native CSS positioning and ss- prefix
- Replace manual positioning with vertical-align: super/sub - Add line-height: 0 to prevent text flow disruption - Rename classes from auto-super/auto-sub to ss-sup/ss-sub - Follow CSS framework naming conventions (tw-, bs-, ss-) - Improve cross-browser consistency and performance BREAKING CHANGE: CSS class names changed from auto-super to ss-sup Authored by: Aaron Lippold<lippold@gmail.com>
1 parent f576e3f commit 8311b3f

File tree

2 files changed

+74
-89
lines changed

2 files changed

+74
-89
lines changed

src/runtime/smartscript/dom.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ export function createSuperscriptElement(
1717

1818
switch (type) {
1919
case 'trademark':
20-
sup.className = 'auto-super trademark-symbol'
20+
sup.className = 'ss-sup ss-tm'
2121
sup.setAttribute('aria-label', 'trademark')
2222
break
2323
case 'registered':
24-
sup.className = 'auto-super registered-symbol'
24+
sup.className = 'ss-sup ss-reg'
2525
sup.setAttribute('aria-label', 'registered')
2626
break
2727
case 'ordinal':
28-
sup.className = 'auto-super ordinal-suffix'
28+
sup.className = 'ss-sup ss-ordinal'
2929
sup.setAttribute('aria-label', content)
3030
break
3131
case 'math':
32-
sup.className = 'auto-super math-notation'
32+
sup.className = 'ss-sup ss-math'
3333
sup.setAttribute('aria-label', `superscript ${content}`)
3434
break
3535
default:
36-
sup.className = 'auto-super'
36+
sup.className = 'ss-sup'
3737
sup.setAttribute('aria-label', `superscript ${content}`)
3838
}
3939

@@ -49,7 +49,7 @@ export function createSubscriptElement(
4949
): HTMLElement {
5050
const sub = document.createElement('sub')
5151
sub.textContent = content
52-
sub.className = 'auto-sub'
52+
sub.className = 'ss-sub'
5353

5454
switch (type) {
5555
case 'chemical':

src/runtime/superscript.css

Lines changed: 68 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,105 @@
11
/* Superscript and Subscript Typography Enhancement Styles */
2-
/* Pure CSS - Framework agnostic */
2+
/* SmartScript (ss-) prefixed classes for automatic typography */
33

4-
/* Auto-generated superscript elements */
5-
sup.auto-super,
6-
.text-super {
7-
/* Spacing for better readability */
8-
margin-left: 0.05em; /* Small space before */
9-
margin-right: 0.1em; /* Slightly more space after */
10-
11-
/* Core superscript styling */
4+
/* ============================================
5+
Core Superscript Styling
6+
Best practice: Use vertical-align: super with line-height: 0
7+
============================================ */
8+
sup.ss-sup {
9+
/* Size reduction */
1210
font-size: 0.75em;
11+
12+
/* Use browser's native superscript positioning */
13+
vertical-align: super;
14+
15+
/* Prevent line-height disruption */
1316
line-height: 0;
14-
vertical-align: super; /* Use browser's native superscript positioning - adapts to font metrics */
1517

16-
/* Visual refinement */
18+
/* Fine-tune position - bring down slightly from browser default */
19+
position: relative;
20+
top: 0.15em; /* Scales with font size */
21+
22+
/* Spacing */
23+
margin-left: 0.05em;
24+
margin-right: 0.1em;
25+
26+
/* Inherit parent styles */
1727
font-weight: inherit;
1828
letter-spacing: 0.025em;
1929
}
2030

21-
/* Auto-generated subscript elements */
22-
sub.auto-sub,
23-
.text-sub {
24-
/* Spacing for better readability */
25-
margin-left: 0.05em; /* Small space before */
26-
margin-right: 0.1em; /* Slightly more space after */
27-
28-
/* Core subscript styling */
31+
/* ============================================
32+
Core Subscript Styling
33+
============================================ */
34+
sub.ss-sub {
35+
/* Size reduction */
2936
font-size: 0.75em;
37+
38+
/* Use browser's native subscript positioning */
39+
vertical-align: sub;
40+
41+
/* Prevent line-height disruption */
3042
line-height: 0;
31-
vertical-align: sub; /* Use browser's native subscript positioning */
3243

33-
/* Visual refinement */
44+
/* Spacing */
45+
margin-left: 0.05em;
46+
margin-right: 0.1em;
47+
48+
/* Inherit parent styles */
3449
font-weight: inherit;
3550
letter-spacing: 0.025em;
3651
}
3752

38-
/* Special handling for consecutive super/subscripts */
39-
sup.auto-super + sup.auto-super,
40-
sub.auto-sub + sub.auto-sub {
41-
margin-left: 0; /* No extra space between consecutive elements */
53+
/* ============================================
54+
Headings: Slightly smaller for visual balance
55+
============================================ */
56+
:is(h1, h2, h3, h4, h5, h6) sup.ss-sup,
57+
:is(h1, h2, h3, h4, h5, h6) sub.ss-sub {
58+
font-size: 0.65em;
4259
}
4360

44-
/* In headings, adjust sizing */
45-
h1 sup.auto-super, h1 sub.auto-sub,
46-
h2 sup.auto-super, h2 sub.auto-sub,
47-
h3 sup.auto-super, h3 sub.auto-sub {
48-
font-size: 0.65em; /* Slightly smaller in headings */
49-
}
61+
/* ============================================
62+
Special Cases
63+
============================================ */
5064

51-
/* Special handling for Unicode trademark and registered symbols */
52-
/* These already have some superscript positioning built into the character */
53-
/* So we need less vertical adjustment */
54-
sup.trademark-symbol {
55-
font-size: 0.8em; /* Slightly larger since the Unicode character is already small */
56-
vertical-align: baseline;
57-
position: relative;
58-
top: -0.3em; /* Reduced from -0.5em to better match registered symbol */
59-
margin-left: 0.05em;
60-
margin-right: 0.05em;
65+
/* Remove spacing between consecutive super/subscripts */
66+
:is(sup.ss-sup, sub.ss-sub) + :is(sup.ss-sup, sub.ss-sub) {
67+
margin-left: 0;
6168
}
6269

63-
/* Registered symbol needs different positioning due to the circle */
64-
sup.registered-symbol {
65-
font-size: 0.8em;
66-
vertical-align: baseline;
67-
position: relative;
68-
top: -0.25em; /* Lower than TM to account for circle - adjusted for better alignment */
69-
margin-left: 0.05em;
70-
margin-right: 0.05em;
70+
/* Specific symbol classes for semantic clarity */
71+
sup.ss-tm {
72+
/* Inherits from ss-sup */
7173
}
7274

73-
/* In headings, raise trademark and registered symbols higher */
74-
h1 sup.trademark-symbol,
75-
h2 sup.trademark-symbol,
76-
h3 sup.trademark-symbol,
77-
h4 sup.trademark-symbol,
78-
h5 sup.trademark-symbol,
79-
h6 sup.trademark-symbol {
80-
top: -0.5em; /* Reduced from -0.7em for better balance */
81-
font-size: 0.65em;
82-
}
83-
84-
/* Registered in headings - slightly lower than TM */
85-
h1 sup.registered-symbol,
86-
h2 sup.registered-symbol,
87-
h3 sup.registered-symbol,
88-
h4 sup.registered-symbol,
89-
h5 sup.registered-symbol,
90-
h6 sup.registered-symbol {
91-
top: -0.4em; /* Slightly lower than TM to account for circle */
92-
font-size: 0.65em;
75+
sup.ss-reg {
76+
/* Inherits from ss-sup */
9377
}
9478

95-
/* Specific adjustments for chemical formulas */
96-
/* Removed first-child rule as it was incorrectly removing margins */
79+
/* ============================================
80+
Media Queries & Accessibility
81+
============================================ */
9782

98-
/* Print styles */
83+
/* Print optimization */
9984
@media print {
100-
sup.auto-super,
101-
sub.auto-sub {
102-
font-size: 0.7em; /* Slightly smaller for print */
85+
sup.ss-sup,
86+
sub.ss-sub {
87+
font-size: 0.7em;
10388
}
10489
}
10590

106-
/* High contrast mode support */
91+
/* High contrast mode */
10792
@media (prefers-contrast: high) {
108-
sup.auto-super,
109-
sub.auto-sub {
110-
font-weight: bold; /* Make more visible in high contrast */
93+
sup.ss-sup,
94+
sub.ss-sub {
95+
font-weight: bold;
11196
}
11297
}
11398

114-
/* Reduce motion support */
99+
/* Reduced motion */
115100
@media (prefers-reduced-motion: reduce) {
116-
sup.auto-super,
117-
sub.auto-sub {
118-
transition: none; /* Remove any transitions */
101+
sup.ss-sup,
102+
sub.ss-sub {
103+
transition: none;
119104
}
120105
}

0 commit comments

Comments
 (0)