aliascss 1.4.5 → 1.5.0
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 +22 -0
- package/bin/aliascss.js +118 -1
- package/dist/aliascss.js +1 -1
- package/lib/classPrinter.js +347 -21
- package/lib/compilers/color.js +5 -5
- package/lib/compilers/gradient.js +3 -3
- package/lib/compilers/stringAndContent.js +2 -1
- package/lib/component-elements.d.ts +155 -0
- package/lib/component-elements.js +223 -0
- package/lib/config.d.ts +2 -0
- package/lib/config.js +3 -1
- package/lib/css-properties-all.js +337 -202
- package/lib/custom-css-compilers.js +49 -116
- package/lib/extras-elements.d.ts +87 -0
- package/lib/extras-elements.js +184 -0
- package/lib/form-elements.d.ts +75 -0
- package/lib/form-elements.js +186 -0
- package/lib/layout-elements.d.ts +59 -0
- package/lib/layout-elements.js +113 -0
- package/lib/nav-elements.d.ts +71 -0
- package/lib/nav-elements.js +243 -0
- 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 +546 -12
- package/lib/prebuild.js +3 -852
- package/lib/prefix/PseudoPrefixNew.js +301 -16
- package/lib/prefix/attribute-selector.js +4 -2
- 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/prefix/pseudoSelectorNew.js +184 -49
- package/lib/prefix/responsive.d.ts +13 -9
- package/lib/prefix/responsive.js +131 -9
- package/lib/returnPropertyAndValue.js +9 -4
- package/lib/returnStatement-bk-291026.d.ts +5 -0
- package/lib/returnStatement-bk-291026.js +470 -0
- package/lib/returnStatement-bk.d.ts +5 -0
- package/lib/returnStatement-bk.js +311 -0
- package/lib/returnStatement.d.ts +1 -0
- package/lib/returnStatement.js +262 -12
- package/lib/static/customStaticClassNames.js +35 -35
- package/lib/static/staticClassNamesAlias.js +18 -16
- package/lib/table-elements.d.ts +39 -0
- package/lib/table-elements.js +90 -0
- package/lib/utils/helper.d.ts +6 -0
- package/lib/utils/helper.js +52 -0
- package/lib/x-classes/x-bundle.d.ts +589 -0
- package/lib/x-classes/x-bundle.js +12 -0
- package/lib/x-classes/x-comps.d.ts +87 -0
- package/lib/x-classes/x-comps.js +189 -0
- package/lib/x-classes/x-extras.d.ts +155 -0
- package/lib/x-classes/x-extras.js +223 -0
- package/lib/x-classes/x-form-components.d.ts +75 -0
- package/lib/x-classes/x-form-components.js +186 -0
- package/lib/x-classes/x-helper-components.d.ts +63 -0
- package/lib/x-classes/x-helper-components.js +91 -0
- package/lib/x-classes/x-layout-components.d.ts +59 -0
- package/lib/x-classes/x-layout-components.js +113 -0
- package/lib/x-classes/x-menu.d.ts +23 -0
- package/lib/x-classes/x-menu.js +55 -0
- package/lib/x-classes/x-navs.d.ts +71 -0
- package/lib/x-classes/x-navs.js +243 -0
- package/lib/x-classes/x-row-col.d.ts +29 -0
- package/lib/x-classes/x-row-col.js +52 -0
- package/lib/x-classes/x-table.d.ts +39 -0
- package/lib/x-classes/x-table.js +90 -0
- package/lib/x-classes/x-theme.d.ts +15 -0
- package/lib/x-classes/x-theme.js +32 -0
- package/lib/x-imports.d.ts +31 -0
- package/lib/x-imports.js +748 -0
- package/package.json +1 -1
package/lib/node/compileFile.js
CHANGED
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import extractClassNamesFromFile from "./extractClassNamesFromFile.js";
|
|
11
|
-
import { compiler as statementMaker } from "../returnStatement.js";
|
|
11
|
+
import { compiler as statementMaker } from "../returnStatement-bk-291026.js";
|
|
12
12
|
import config from "../config.js";
|
|
13
13
|
import fs from "fs";
|
|
14
14
|
import fg from "fast-glob";
|
|
@@ -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
|
+
*/
|