Skip to content

Commit 338f974

Browse files
committed
Fix n m logic
1 parent 9f878eb commit 338f974

File tree

4 files changed

+84
-73
lines changed

4 files changed

+84
-73
lines changed

.changeset/poor-candles-vanish.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@devup-ui/wasm": patch
3+
---
4+
5+
Fix n, m logic to avoid adblock

libs/css/src/constant.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ pub(super) static F_RGBA_RE: Lazy<Regex> =
163163
pub(super) static F_RGB_RE: Lazy<Regex> =
164164
Lazy::new(|| Regex::new(r"rgb\((\d+),(\d+),(\d+)\)").unwrap());
165165

166-
pub(super) static N_BASE_ARRAY: [char; 26] = [
166+
pub(super) static N_BASE_ARRAY: [char; 27] = [
167167
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
168-
't', 'u', 'v', 'w', 'x', 'y', 'z',
168+
't', 'u', 'v', 'w', 'x', 'y', 'z', '_',
169169
];
170170

171-
pub(super) static M_BASE_ARRAY: [char; 36] = [
171+
pub(super) static M_BASE_ARRAY: [char; 37] = [
172172
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
173-
't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
173+
't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_',
174174
];

libs/css/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ pub fn sheet_to_classname(
155155
});
156156
if !filename.is_empty() {
157157
format!(
158-
// avoid g-ad class (google ad)
159-
"{}_{}",
158+
"{}-{}",
160159
num_to_nm_base(get_file_num_by_filename(&filename)),
161160
clas_num
162161
)

libs/css/src/num_to_nm_base.rs

Lines changed: 74 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ pub fn num_to_nm_base(num: usize) -> String {
2424
}
2525
}
2626
}
27-
result
27+
if result.ends_with("ad") {
28+
// avoid g-ad class (google ad)
29+
result.replace("ad", "a-d")
30+
} else {
31+
result
32+
}
2833
}
2934

3035
#[cfg(test)]
@@ -59,72 +64,74 @@ mod tests {
5964
#[case(23, "x")]
6065
#[case(24, "y")]
6166
#[case(25, "z")]
62-
#[case(26, "aa")]
63-
#[case(27, "ab")]
64-
#[case(28, "ac")]
65-
#[case(29, "ad")]
66-
#[case(30, "ae")]
67-
#[case(31, "af")]
68-
#[case(32, "ag")]
69-
#[case(33, "ah")]
70-
#[case(34, "ai")]
71-
#[case(35, "aj")]
72-
#[case(36, "ak")]
73-
#[case(37, "al")]
74-
#[case(38, "am")]
75-
#[case(39, "an")]
76-
#[case(40, "ao")]
77-
#[case(41, "ap")]
78-
#[case(42, "aq")]
79-
#[case(43, "ar")]
80-
#[case(44, "as")]
81-
#[case(45, "at")]
82-
#[case(46, "au")]
83-
#[case(47, "av")]
84-
#[case(48, "aw")]
85-
#[case(49, "ax")]
86-
#[case(50, "ay")]
87-
#[case(51, "az")]
88-
#[case(52, "a0")]
89-
#[case(53, "a1")]
90-
#[case(54, "a2")]
91-
#[case(55, "a3")]
92-
#[case(56, "a4")]
93-
#[case(57, "a5")]
94-
#[case(58, "a6")]
95-
#[case(59, "a7")]
96-
#[case(60, "a8")]
97-
#[case(61, "a9")]
98-
#[case(62, "ba")]
99-
#[case(63, "bb")]
100-
#[case(64, "bc")]
101-
#[case(65, "bd")]
102-
#[case(66, "be")]
103-
#[case(67, "bf")]
104-
#[case(68, "bg")]
105-
#[case(69, "bh")]
106-
#[case(70, "bi")]
107-
#[case(71, "bj")]
108-
#[case(72, "bk")]
109-
#[case(73, "bl")]
110-
#[case(74, "bm")]
111-
#[case(75, "bn")]
112-
#[case(76, "bo")]
113-
#[case(77, "bp")]
114-
#[case(78, "bq")]
115-
#[case(79, "br")]
116-
#[case(80, "bs")]
117-
#[case(81, "bt")]
118-
#[case(82, "bu")]
119-
#[case(83, "bv")]
120-
#[case(84, "bw")]
121-
#[case(85, "bx")]
122-
#[case(86, "by")]
123-
#[case(87, "bz")]
124-
#[case(88, "b0")]
125-
#[case(89, "b1")]
126-
#[case(961, "z9")]
127-
#[case(962, "aaa")]
67+
#[case(26, "_")]
68+
#[case(27, "aa")]
69+
#[case(28, "ab")]
70+
#[case(29, "ac")]
71+
#[case(30, "a-d")]
72+
#[case(31, "ae")]
73+
#[case(32, "af")]
74+
#[case(33, "ag")]
75+
#[case(34, "ah")]
76+
#[case(35, "ai")]
77+
#[case(36, "aj")]
78+
#[case(37, "ak")]
79+
#[case(38, "al")]
80+
#[case(39, "am")]
81+
#[case(40, "an")]
82+
#[case(41, "ao")]
83+
#[case(42, "ap")]
84+
#[case(43, "aq")]
85+
#[case(44, "ar")]
86+
#[case(45, "as")]
87+
#[case(46, "at")]
88+
#[case(47, "au")]
89+
#[case(48, "av")]
90+
#[case(49, "aw")]
91+
#[case(50, "ax")]
92+
#[case(51, "ay")]
93+
#[case(52, "az")]
94+
#[case(53, "a0")]
95+
#[case(54, "a1")]
96+
#[case(55, "a2")]
97+
#[case(56, "a3")]
98+
#[case(57, "a4")]
99+
#[case(58, "a5")]
100+
#[case(59, "a6")]
101+
#[case(60, "a7")]
102+
#[case(61, "a8")]
103+
#[case(62, "a9")]
104+
#[case(63, "a_")]
105+
#[case(64, "ba")]
106+
#[case(65, "bb")]
107+
#[case(66, "bc")]
108+
#[case(67, "bd")]
109+
#[case(68, "be")]
110+
#[case(69, "bf")]
111+
#[case(70, "bg")]
112+
#[case(71, "bh")]
113+
#[case(72, "bi")]
114+
#[case(73, "bj")]
115+
#[case(74, "bk")]
116+
#[case(75, "bl")]
117+
#[case(76, "bm")]
118+
#[case(77, "bn")]
119+
#[case(78, "bo")]
120+
#[case(79, "bp")]
121+
#[case(80, "bq")]
122+
#[case(81, "br")]
123+
#[case(82, "bs")]
124+
#[case(83, "bt")]
125+
#[case(84, "bu")]
126+
#[case(85, "bv")]
127+
#[case(86, "bw")]
128+
#[case(87, "bx")]
129+
#[case(88, "by")]
130+
#[case(89, "bz")]
131+
#[case(90, "b0")]
132+
#[case(91, "b1")]
133+
#[case(987, "z9")]
134+
#[case(1026, "aaa")]
128135
fn test_num_to_nm_base_rstest(#[case] input: usize, #[case] expected: &str) {
129136
assert_eq!(num_to_nm_base(input), expected);
130137
}

0 commit comments

Comments
 (0)