aliascss 1.4.7 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/bin/aliascss.js +118 -1
- package/dist/aliascss.js +1 -1
- package/jestconfig.json +1 -3
- package/lib/build/index.js +136 -19
- package/lib/classPrinter.d.ts +1 -1
- package/lib/classPrinter.js +351 -23
- package/lib/compilers/border.js +106 -27
- package/lib/compilers/clipPath.js +79 -6
- package/lib/compilers/color.js +150 -21
- package/lib/compilers/filter.js +90 -3
- package/lib/compilers/font.js +39 -11
- package/lib/compilers/gradient.js +43 -27
- package/lib/compilers/length.js +34 -9
- package/lib/compilers/shadow.js +60 -26
- package/lib/compilers/stringAndContent.js +39 -2
- package/lib/compilers/timingFunction.js +57 -6
- package/lib/compilers/transform.js +118 -48
- package/lib/compilers/transition.js +79 -11
- package/lib/compilers/url.js +53 -3
- package/lib/config.d.ts +1 -0
- package/lib/config.js +1 -0
- package/lib/custom-css-compilers.js +1 -68
- package/lib/index.d.ts +9 -9
- package/lib/node/compileFile-BK-291026.d.ts +27 -0
- package/lib/node/compileFile-BK-291026.js +309 -0
- package/lib/node/compileFile-bk.d.ts +14 -12
- package/lib/node/compileFile-bk.js +263 -252
- package/lib/node/compileFile.js +1 -1
- package/lib/node/extractClassNamesFromFile.js +208 -86
- package/lib/prebuild.d.ts +26 -0
- package/lib/prebuild.js +0 -6
- package/lib/prefix/element-selector.js +93 -20
- package/lib/prefix/extractPrefix.d.ts +1 -1
- package/lib/prefix/extractPrefix.js +113 -70
- package/lib/returnPropertyAndValue-bk-301026.d.ts +30 -0
- package/lib/returnPropertyAndValue-bk-301026.js +219 -0
- package/lib/returnPropertyAndValue.js +26 -25
- package/lib/returnStatement-bk-291026.d.ts +5 -0
- package/lib/returnStatement-bk-291026.js +470 -0
- package/lib/returnStatement.d.ts +1 -0
- package/lib/returnStatement.js +120 -29
- package/lib/utils/helper.js +16 -2
- package/lib/x-classes/x-bundle.d.ts +26 -0
- package/lib/x-classes/x-bundle.js +2 -1
- package/lib/x-classes/x-extras.js +1 -1
- package/lib/x-classes/x-form-components.js +2 -1
- package/lib/x-classes/x-row-col.d.ts +29 -0
- package/lib/x-classes/x-row-col.js +52 -0
- package/llms.txt +326 -0
- package/package.json +3 -1
- package/tsconfig.json +1 -0
- package/tsconfig.test.json +10 -0
package/lib/node/compileFile.js
CHANGED
|
@@ -62,7 +62,7 @@ export function globalCSSCompiler() {
|
|
|
62
62
|
let basePreamble = "";
|
|
63
63
|
// 1. Layer declaration
|
|
64
64
|
if (Array.isArray(init.layers) && init.layers.length > 0) {
|
|
65
|
-
basePreamble += `@layer ${init.layers.join(", ")};\n\n`;
|
|
65
|
+
basePreamble += `@layer ${init.layers.join(", ")};\n\n @layer reset{[hidden]:not([hidden="until-found"]){display:none!important}}\n\n`;
|
|
66
66
|
init.initializedLayer = true;
|
|
67
67
|
}
|
|
68
68
|
// 2. Custom CSS statements & group statements
|
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
+
// data-raw-css="…" or '…' (may span lines)
|
|
3
|
+
const RAW_CSS = /data-raw-css=(["'])([\s\S]*?)\1/g;
|
|
4
|
+
// Attribute values in source files keep their HTML entities: decode the common ones,
|
|
5
|
+
// otherwise data-raw-css="content:"x"" ends up as " in the CSS file.
|
|
6
|
+
const ENTITIES = { '"': '"', '"': '"', ''': "'", ''': "'", '<': '<', '>': '>', '&': '&' };
|
|
7
|
+
const decodeEntities = (s) => s.replace(/&(?:quot|#34|#39|apos|lt|gt|amp);/g, (m) => ENTITIES[m]);
|
|
8
|
+
// Every match of `re` in `text`, using a global copy (the config regexes have no "g" flag)
|
|
9
|
+
function allMatches(text, re) {
|
|
10
|
+
const flags = re.flags.includes('g') ? re.flags : re.flags + 'g';
|
|
11
|
+
return [...text.matchAll(new RegExp(re.source, flags))];
|
|
12
|
+
}
|
|
13
|
+
const words = (value) => value.trim().split(/\s+/).filter(Boolean);
|
|
2
14
|
export default function extractClassNamesFromFile(file, config) {
|
|
3
15
|
const data = fs.readFileSync(file, 'utf-8');
|
|
4
|
-
|
|
16
|
+
// Sets: indexOf on arrays made this O(n²) on large files.
|
|
17
|
+
// Also: `config.ignore?.indexOf(e) === -1` is false when ignore is undefined,
|
|
18
|
+
// which silently dropped every class. A missing list now means "ignore nothing".
|
|
19
|
+
const ignore = new Set(config.ignore || []);
|
|
20
|
+
const classes = new Set();
|
|
21
|
+
const addClasses = (value) => {
|
|
22
|
+
for (const e of words(value))
|
|
23
|
+
if (!ignore.has(e))
|
|
24
|
+
classes.add(e);
|
|
25
|
+
};
|
|
5
26
|
const groups = {};
|
|
6
27
|
const keyframes = {};
|
|
7
28
|
let rawCSSStatement = '';
|
|
@@ -9,112 +30,213 @@ export default function extractClassNamesFromFile(file, config) {
|
|
|
9
30
|
const matchCSSModuleFunction = config.useCSSModule ? config.matchCSSModuleFunction : null;
|
|
10
31
|
const matchRegExp = config.useColon ? config.matchRegExpWithColon : config.matchRegExp;
|
|
11
32
|
const matchRegExpKeyFrame = config.useColon ? config.matchRegExpWithColonKeyFrame : config.matchRegExpKeyFrame;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
33
|
+
// 0. data-raw-css="…"
|
|
34
|
+
for (const m of data.matchAll(RAW_CSS)) {
|
|
35
|
+
if (m[2])
|
|
36
|
+
rawCSSStatement += decodeEntities(m[2]) + '\n';
|
|
37
|
+
}
|
|
38
|
+
// 1 - i. Extractor function, e.g. String`…`
|
|
39
|
+
if (matchExtractorFunction) {
|
|
40
|
+
for (const m of allMatches(data, matchExtractorFunction)) {
|
|
41
|
+
if (m[2])
|
|
42
|
+
addClasses(m[2]);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// 1 - ii. CSS modules
|
|
46
|
+
if (matchCSSModuleFunction) {
|
|
47
|
+
for (const m of allMatches(data, matchCSSModuleFunction)) {
|
|
48
|
+
if (!m[1])
|
|
49
|
+
continue;
|
|
50
|
+
const name = 'module=' + m[1].replace(/[\s]/g, '\\ ').replace(/([.%=\]\[@~:*#\(\)\/^])/g, '\\$1');
|
|
51
|
+
groups[name] = words(m[1]).join(' ');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// 2. keyframes-name="…"
|
|
55
|
+
for (const m of allMatches(data, matchRegExpKeyFrame)) {
|
|
56
|
+
if (!/^keyframes[:_-]/.test(m[1]))
|
|
57
|
+
continue;
|
|
58
|
+
const name = m[1].replace(/^keyframes[:_-]/, '');
|
|
59
|
+
if (!name)
|
|
60
|
+
continue;
|
|
61
|
+
const value = words(m[2]).join(' ');
|
|
62
|
+
keyframes[name] = keyframes.hasOwnProperty(name) ? keyframes[name] + ' ' + value : value;
|
|
63
|
+
}
|
|
64
|
+
// 3. class / className / class:group attributes
|
|
65
|
+
for (const m of allMatches(data, matchRegExp)) {
|
|
66
|
+
// Skip matches inside a longer attribute name: data-class-name="…" or myclass="…"
|
|
67
|
+
const before = m.index ? data[m.index - 1] : '';
|
|
68
|
+
if (before && /[\w-]/.test(before))
|
|
69
|
+
continue;
|
|
70
|
+
const attr = m[1];
|
|
71
|
+
if (/^(class|className)$/.test(attr)) {
|
|
72
|
+
addClasses(m[2]);
|
|
73
|
+
}
|
|
74
|
+
else if (/^class[:_-]/.test(attr)) { // anchored: data-class-x is not a group
|
|
75
|
+
let group = attr.replace(/^class[:_-]/, '');
|
|
76
|
+
let classExtracted = m[2];
|
|
77
|
+
const scope = group.match(/\[(.)+\]/);
|
|
78
|
+
if (scope) {
|
|
79
|
+
group = group.replace(scope[0], '');
|
|
80
|
+
const prefix = scope[0].replace(/^\[/, '').replace(/\]$/, '');
|
|
81
|
+
classExtracted = words(classExtracted).map(e => prefix + (/^[_-]/.test(e) ? '' : '-') + e).join(' ');
|
|
82
|
+
}
|
|
83
|
+
if (group && classExtracted.trim()) {
|
|
84
|
+
const value = words(classExtracted).join(' ');
|
|
85
|
+
groups[group] = groups.hasOwnProperty(group) ? groups[group] + ' ' + value : value;
|
|
86
|
+
}
|
|
23
87
|
}
|
|
24
88
|
}
|
|
89
|
+
return [[...classes], groups, keyframes, rawCSSStatement];
|
|
90
|
+
}
|
|
91
|
+
/*
|
|
92
|
+
import fs from 'fs';
|
|
93
|
+
|
|
94
|
+
type config={
|
|
95
|
+
matchExtractorFunction:RegExp|null,
|
|
96
|
+
matchRegExp:RegExp,
|
|
97
|
+
matchRegExpWithColon:RegExp,
|
|
98
|
+
matchRegExpKeyFrame:RegExp,
|
|
99
|
+
matchRegExpWithColonKeyFrame:RegExp
|
|
100
|
+
useColon:boolean,
|
|
101
|
+
useExtractorFunction:boolean,
|
|
102
|
+
|
|
103
|
+
useCSSModule:boolean,
|
|
104
|
+
matchCSSModuleFunction:RegExp|null,
|
|
105
|
+
|
|
106
|
+
ignore?:string[],
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export default function extractClassNamesFromFile(file:string,config:config):[string[],{[key:string]:string},{[key:string]:string},string]{
|
|
110
|
+
const data = fs.readFileSync(file, 'utf-8');
|
|
111
|
+
const classList:string[] = [];
|
|
112
|
+
const groups :{[key:string]:string}= {};
|
|
113
|
+
const keyframes:{[key:string]:string}= {};
|
|
114
|
+
let rawCSSStatement='';
|
|
115
|
+
|
|
116
|
+
const matchExtractorFunction=config.useExtractorFunction?config.matchExtractorFunction:null;
|
|
117
|
+
|
|
118
|
+
const matchCSSModuleFunction=config.useCSSModule?config.matchCSSModuleFunction:null;
|
|
119
|
+
|
|
120
|
+
const matchRegExp=config.useColon?config.matchRegExpWithColon:config.matchRegExp;
|
|
121
|
+
const matchRegExpKeyFrame=config.useColon?config.matchRegExpWithColonKeyFrame:config.matchRegExpKeyFrame;
|
|
122
|
+
const matchRegExpRawCSSStatement=/data-raw-css=(["'])([\s\S]*?)\1/; // data-raw-css=(["'])(.*?)\1/s
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
// 0. data-raw-css=
|
|
126
|
+
if(data.match(matchRegExpRawCSSStatement)){
|
|
127
|
+
const matchesRawCSS=data.match(new RegExp(matchRegExpRawCSSStatement,"g"));
|
|
128
|
+
if(matchesRawCSS){
|
|
129
|
+
matchesRawCSS.forEach((each)=>{
|
|
130
|
+
const extraction=each.match(matchRegExpRawCSSStatement);
|
|
131
|
+
if(extraction && extraction[2]){
|
|
132
|
+
rawCSSStatement+=extraction[2]+'\n';
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
}
|
|
138
|
+
|
|
25
139
|
// 1 - i. Extract from Extractor function
|
|
26
|
-
if
|
|
27
|
-
const matchesEF
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
140
|
+
if(config.useExtractorFunction && matchExtractorFunction){
|
|
141
|
+
const matchesEF=data.match(new RegExp(matchExtractorFunction,"g"))
|
|
142
|
+
if(matchesEF){
|
|
143
|
+
matchesEF.forEach((each)=>{
|
|
144
|
+
const extraction=each.match(matchExtractorFunction);
|
|
145
|
+
if(extraction && extraction[2]){
|
|
146
|
+
extraction[2].trim().replace(/[\s]+/," ").split(/\s+/).forEach((e) => {
|
|
147
|
+
if (config.ignore?.indexOf(e) === -1 && classList.indexOf(e) === -1) {
|
|
148
|
+
classList.push(e);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
}
|
|
153
|
+
})
|
|
38
154
|
}
|
|
39
|
-
});
|
|
40
155
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
156
|
+
// 1 -ii. CSS-Module
|
|
157
|
+
if(config.useCSSModule && matchCSSModuleFunction){
|
|
158
|
+
const matchesEF=data.match(new RegExp(matchCSSModuleFunction,"g"))
|
|
159
|
+
if(matchesEF){
|
|
160
|
+
matchesEF.forEach((each)=>{
|
|
161
|
+
const extraction=each.match(matchCSSModuleFunction);
|
|
162
|
+
if(extraction && extraction[1]){
|
|
163
|
+
groups[`module=${extraction[1].replace(/[\s]/g,'\\ ').replace(/([.%=\]\[@~:*#\(\)\/^])/g,'\\$1')}`]=extraction[1].trim().replace(/[\s]+/," ")
|
|
164
|
+
|
|
165
|
+
}
|
|
166
|
+
})
|
|
50
167
|
}
|
|
51
|
-
});
|
|
52
168
|
}
|
|
53
|
-
}
|
|
54
169
|
// 2. Extract KeyFrames
|
|
55
|
-
const matchesKF
|
|
56
|
-
|
|
170
|
+
const matchesKF= data.match(new RegExp(matchRegExpKeyFrame,"g"));
|
|
171
|
+
if(matchesKF){
|
|
172
|
+
|
|
57
173
|
matchesKF.forEach((match) => {
|
|
58
174
|
const extraction = match.match(matchRegExpKeyFrame);
|
|
59
|
-
if
|
|
60
|
-
|
|
175
|
+
if(!extraction) return;
|
|
176
|
+
|
|
61
177
|
// case one if its just keyframes
|
|
62
|
-
if
|
|
63
|
-
const name
|
|
178
|
+
if(extraction[1].match(/keyframes[:_-]/)){
|
|
179
|
+
const name=extraction[1].replace(/keyframes[:_-]/,'');
|
|
64
180
|
if (name) {
|
|
65
181
|
// if name already exists
|
|
66
182
|
// if (names.hasOwnProperty(name) && names[name] === extraction[2]) {
|
|
67
|
-
if (keyframes.hasOwnProperty(name))
|
|
68
|
-
|
|
183
|
+
if (keyframes.hasOwnProperty(name)){
|
|
184
|
+
keyframes[name] = keyframes[name] +" "+ extraction[2].trim().replace(/[\s]+/," ");
|
|
69
185
|
}
|
|
70
186
|
else {
|
|
71
187
|
// new name
|
|
72
|
-
keyframes[name] = extraction[2].trim().replace(/[\s]+/,
|
|
73
|
-
|
|
74
|
-
|
|
188
|
+
keyframes[name] = extraction[2].trim().replace(/[\s]+/," ");
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
})
|
|
75
194
|
}
|
|
76
|
-
|
|
77
|
-
}
|
|
195
|
+
|
|
78
196
|
// 3 .Extract from class|className|group attribute
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
matches
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
if (group && classExtracted) {
|
|
104
|
-
if (groups.hasOwnProperty(group)) {
|
|
105
|
-
groups[group] = groups[group] + " " + classExtracted;
|
|
197
|
+
const matches=data.match(new RegExp(matchRegExp,"g"));
|
|
198
|
+
|
|
199
|
+
if(matches?.length){
|
|
200
|
+
matches.forEach(toEach=>{
|
|
201
|
+
const each=toEach.match(matchRegExp);
|
|
202
|
+
if(!each) return;
|
|
203
|
+
if(each[1].match(/^(class|className)$/)){
|
|
204
|
+
each[2].split(/\s+/).forEach(e=>{
|
|
205
|
+
|
|
206
|
+
if(config.ignore?.indexOf(e)===-1 && classList.indexOf(e)===-1){
|
|
207
|
+
classList.push(e);
|
|
208
|
+
}
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
}else if(each[1].match(/class[:_-]/)){
|
|
212
|
+
// Group
|
|
213
|
+
let group=each[1].replace(/class[:_-]/,'');
|
|
214
|
+
let classExtracted=each[2];
|
|
215
|
+
const match=group.match(/\[(.)+\]/);
|
|
216
|
+
if(match){
|
|
217
|
+
// console.log(match);
|
|
218
|
+
group=group.replace(match[0],'');
|
|
219
|
+
classExtracted=classExtracted.trim().split(/\s+/).map(e=>match[0].replace(/^\[/,'').replace(/\]$/,'')+(/^[_-]/.test(e)?'':'-')+e).join(" ");
|
|
106
220
|
}
|
|
107
|
-
|
|
108
|
-
|
|
221
|
+
|
|
222
|
+
if(group && classExtracted){
|
|
223
|
+
if(groups.hasOwnProperty(group)){
|
|
224
|
+
groups[group] = groups[group] +" "+ classExtracted;
|
|
225
|
+
}else{
|
|
226
|
+
groups[group] = classExtracted.trim().replace(/[\s]+/," ");
|
|
227
|
+
}
|
|
109
228
|
}
|
|
110
229
|
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
}
|
|
233
|
+
// ?.join(' ')
|
|
234
|
+
// .replace(/class(Name)?=/g,'')
|
|
235
|
+
// .replace(/["']/g,'')
|
|
236
|
+
// .split(/\s+/)
|
|
237
|
+
|
|
238
|
+
|
|
118
239
|
// extract from keyframes
|
|
119
|
-
return [classList,
|
|
240
|
+
return [classList,groups,keyframes,rawCSSStatement]
|
|
120
241
|
}
|
|
242
|
+
*/
|
package/lib/prebuild.d.ts
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
+
'x-row': {
|
|
3
|
+
type: string;
|
|
4
|
+
compiler: (value: string) => string;
|
|
5
|
+
groups: {
|
|
6
|
+
'': string;
|
|
7
|
+
xs: string;
|
|
8
|
+
sm: string;
|
|
9
|
+
md: string;
|
|
10
|
+
lg: string;
|
|
11
|
+
xl: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
'x-col': {
|
|
15
|
+
type: string;
|
|
16
|
+
compiler: (value: string) => string;
|
|
17
|
+
groups: {
|
|
18
|
+
[k: string]: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
'x-col-offset': {
|
|
22
|
+
type: string;
|
|
23
|
+
compiler: (value: string) => string;
|
|
24
|
+
groups: {
|
|
25
|
+
[k: string]: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
2
28
|
'x-absolute-0': {
|
|
3
29
|
type: string;
|
|
4
30
|
statement: string;
|
package/lib/prebuild.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
1
|
import xUtils from './x-imports.js';
|
|
2
|
-
// import formComponents from './form-elements.js';
|
|
3
|
-
// import tableComponents from './table-elements.js';
|
|
4
|
-
// import components from './component-elements.js';
|
|
5
|
-
// import layout from './layout-elements.js';
|
|
6
|
-
// import extrasComponents from './extras-elements.js';
|
|
7
|
-
// import navContent from './nav-elements.js';
|
|
8
2
|
import xComponents from './x-classes/x-bundle.js';
|
|
9
3
|
export default Object.assign(Object.assign({}, xUtils), xComponents);
|
|
@@ -1,26 +1,99 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Element / combinator prefix: _li-… __a-… ___p-… ____p-… _.card-… _all-…
|
|
3
|
+
// New: a class name with "-" goes in parentheses: _.(card-title)-c-red
|
|
4
|
+
// → " .card-title" (also compound: _.(card.is-active)-o-1 → " .card.is-active")
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
// Placeholders for .(…) groups: never contain "-", "_" or letters the rules below touch
|
|
7
|
+
const OPEN = '\u0001';
|
|
8
|
+
const CLOSE = '\u0002';
|
|
9
|
+
// Replace each ".(…)" with ".␁N␂" so the selector regex doesn't stop at its "-".
|
|
10
|
+
// Uses balanced parentheses, so nested (…) inside the group is kept intact.
|
|
11
|
+
function maskParenClasses(str, saved) {
|
|
12
|
+
let out = '';
|
|
13
|
+
for (let i = 0; i < str.length; i++) {
|
|
14
|
+
if (str[i] === '.' && str[i + 1] === '(') {
|
|
15
|
+
let depth = 0;
|
|
16
|
+
let j = i + 1;
|
|
17
|
+
for (; j < str.length; j++) {
|
|
18
|
+
if (str[j] === '(')
|
|
19
|
+
depth++;
|
|
20
|
+
else if (str[j] === ')' && --depth === 0)
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
if (j >= str.length)
|
|
24
|
+
return null; // unbalanced: invalid class
|
|
25
|
+
const inner = str.slice(i + 2, j);
|
|
26
|
+
if (!/^[A-Za-z_][\w.-]*$/.test(inner))
|
|
27
|
+
return null; // only class names, optionally chained with "."
|
|
28
|
+
saved.push(inner);
|
|
29
|
+
out += '.' + OPEN + (saved.length - 1) + CLOSE;
|
|
30
|
+
i = j;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
out += str[i];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
const restore = (str, saved) => str.replace(new RegExp(OPEN + '(\\d+)' + CLOSE, 'g'), (_m, n) => saved[Number(n)]);
|
|
1
39
|
const element = {
|
|
2
|
-
test:
|
|
40
|
+
test: new RegExp('^_[_]?[A-Za-z0-9_.,' + OPEN + CLOSE + ']+(?=[@_[-])'),
|
|
3
41
|
process(className) {
|
|
4
|
-
const
|
|
5
|
-
|
|
42
|
+
const saved = [];
|
|
43
|
+
const masked = maskParenClasses(className, saved);
|
|
44
|
+
if (masked === null)
|
|
45
|
+
return undefined;
|
|
46
|
+
const match = masked.match(this.test);
|
|
47
|
+
if (!match)
|
|
48
|
+
return undefined;
|
|
49
|
+
const alias = match[0];
|
|
50
|
+
const result = alias
|
|
51
|
+
// keywords only as whole segments: _child_ _next_ _siblings_ (never inside a class name)
|
|
52
|
+
.replace(/(^|_)next(?=_)/g, '$1 + ')
|
|
53
|
+
.replace(/(^|_)child(?=_)/g, '$1 > ')
|
|
54
|
+
.replace(/(^|_)siblings(?=_)/g, '$1 ~ ')
|
|
55
|
+
.replace(/____/g, ' ~ ')
|
|
56
|
+
.replace(/___/g, ' + ')
|
|
57
|
+
.replace(/__/g, ' > ')
|
|
58
|
+
.replace(/_/g, ' ')
|
|
59
|
+
.replace(/(^|\s)all(?=\s|$)/g, '$1* ')
|
|
60
|
+
.replace(/[\s]+/g, ' ').trim();
|
|
61
|
+
const rest = masked.replace(alias, (/[^_][_]$/.test(alias) ? '_' : ''));
|
|
62
|
+
return [restore(rest, saved), ' ' + restore(result, saved)];
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
export default element;
|
|
66
|
+
/*
|
|
67
|
+
const element :{
|
|
68
|
+
[key:string]:any,
|
|
69
|
+
process: (...args: any[]) => any
|
|
70
|
+
}
|
|
71
|
+
= {
|
|
72
|
+
test:/^_[_]?[A-Za-z0-9_\.,]+(?=[@_[-])/,
|
|
73
|
+
process(className :string){
|
|
74
|
+
const match=className.match(this.test);
|
|
75
|
+
if(match){
|
|
6
76
|
const alias = match[0];
|
|
7
|
-
if
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
77
|
+
if(match)
|
|
78
|
+
if (alias) {
|
|
79
|
+
const result = alias
|
|
80
|
+
.replace('next',' + ')
|
|
81
|
+
.replace('child',' > ')
|
|
82
|
+
.replace('siblings',' ~')
|
|
83
|
+
.replace(/____/g, ' ~ ')
|
|
84
|
+
.replace(/___/g, ' + ')
|
|
85
|
+
.replace(/__/g, ' > ')
|
|
86
|
+
.replace(/_/g, ' ')
|
|
87
|
+
.replace(/[\s]all/, ' * ')
|
|
88
|
+
//.replace(/[\s](dot)/g, (e, a) => { return ' .' + a.toLowerCase();})
|
|
89
|
+
// .replace(/[\s]([A-Z])/g, (e, a) => { return ' .' + a.toLowerCase();})
|
|
90
|
+
.replace(/[\s]+/g," ").trim();
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
return [className.replace(alias, (/[^_][_]$/.test(alias)?'_':'')), ' ' + result];
|
|
94
|
+
}
|
|
23
95
|
}
|
|
24
96
|
}
|
|
25
|
-
}
|
|
97
|
+
}
|
|
26
98
|
export default element;
|
|
99
|
+
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function extractPrefix(className: string): string
|
|
1
|
+
export default function extractPrefix(className: string): [string, string];
|