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
|
@@ -1,29 +1,48 @@
|
|
|
1
|
+
import timingFunction from './timingFunction.js';
|
|
1
2
|
export default function transition(data) {
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
// a lone duration: 200ms, 0.3s, 0d3s
|
|
4
|
+
if (data.match(/^-?\d*[.d]?\d+(ms|s)$/))
|
|
5
|
+
return data.replace(/^-/, '').replace(/(\d)d(\d)/, '$1.$2');
|
|
4
6
|
let holder = '';
|
|
5
7
|
data
|
|
6
8
|
.replace(/^-/, '')
|
|
7
9
|
.split(/__/)
|
|
8
10
|
.forEach((e) => {
|
|
11
|
+
// a whole layer can be a variable: opacity-200ms__--x
|
|
12
|
+
if (/^--[a-zA-Z]/.test(e)) {
|
|
13
|
+
holder += 'var(' + e + '),';
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
9
16
|
let cssVar = '';
|
|
10
|
-
if (e.match(
|
|
11
|
-
cssVar = '--' + e.split(
|
|
17
|
+
if (e.match(/--[a-zA-Z]/)) {
|
|
18
|
+
cssVar = '--' + e.split(/--(?=[a-zA-Z])/)[1];
|
|
12
19
|
e = e.replace(cssVar, '');
|
|
13
20
|
}
|
|
14
|
-
|
|
21
|
+
// property, duration, then everything else (easing, delay, allow-discrete)
|
|
22
|
+
const m = e.match(/^([a-z-]+)([0-9]+[d.]?[0-9]*m?s)(.*)$/);
|
|
15
23
|
if (!m) {
|
|
16
24
|
if (cssVar)
|
|
17
|
-
|
|
25
|
+
holder += 'var(' + cssVar + '),';
|
|
18
26
|
return;
|
|
19
27
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
28
|
+
let rest = m[3];
|
|
29
|
+
// delay: a time at the end -> opacity-200ms-ease-100ms
|
|
30
|
+
let delay = '';
|
|
31
|
+
const dm = rest.match(/-(-?[0-9]+(?:[d.][0-9]+)?m?s)$/);
|
|
32
|
+
if (dm) {
|
|
33
|
+
delay = dm[1].replace(/(\d)d(\d)/, '$1.$2');
|
|
34
|
+
rest = rest.slice(0, dm.index);
|
|
23
35
|
}
|
|
24
|
-
|
|
25
|
-
|
|
36
|
+
// transition-behavior
|
|
37
|
+
let discrete = '';
|
|
38
|
+
if (/-allow-discrete$/.test(rest)) {
|
|
39
|
+
discrete = 'allow-discrete';
|
|
40
|
+
rest = rest.replace(/-allow-discrete$/, '');
|
|
26
41
|
}
|
|
42
|
+
// easing: keywords, cb-…, steps-… (same rules as transition-timing-function)
|
|
43
|
+
const tf = rest.replace(/^-/, '');
|
|
44
|
+
const easing = tf ? (func[tf] || timingFunction(tf, {}) || '') : '';
|
|
45
|
+
holder += [m[1].replace(/-$/, ''), m[2].replace(/d/, '.'), easing, delay, discrete].filter(Boolean).join(' ') + ',';
|
|
27
46
|
if (cssVar)
|
|
28
47
|
holder += ' var(' + cssVar + ')';
|
|
29
48
|
});
|
|
@@ -45,3 +64,52 @@ const func = {
|
|
|
45
64
|
se: 'step-end',
|
|
46
65
|
'step-end': 'step-end',
|
|
47
66
|
};
|
|
67
|
+
/*
|
|
68
|
+
export default function transition(data: string) {
|
|
69
|
+
|
|
70
|
+
if(data.match(/^-?\d*\.?\d+(ms|s)$/)) return data.replace(/^-/,'');
|
|
71
|
+
let holder = '';
|
|
72
|
+
|
|
73
|
+
data
|
|
74
|
+
.replace(/^-/, '')
|
|
75
|
+
.split(/__/)
|
|
76
|
+
.forEach((e) => {
|
|
77
|
+
let cssVar='';
|
|
78
|
+
if(e.match(/--/)){
|
|
79
|
+
cssVar='--'+e.split(/--/)[1];
|
|
80
|
+
e=e.replace(cssVar,'');
|
|
81
|
+
}
|
|
82
|
+
const m = e.match(/^([a-z-]+)([0-9]+[d|/.]?[0-9]*[m]?[s])([\w-_]*)/);
|
|
83
|
+
|
|
84
|
+
if (!m){
|
|
85
|
+
if(cssVar) return e+" var("+cssVar+")";
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
const tf = m[3].replace(/^-/, '');
|
|
89
|
+
if (tf && func[tf]) {
|
|
90
|
+
holder += m[1].replace(/-$/, '') + ' ' + m[2].replace(/d/, '.') + ' ' + func[tf] + ',';
|
|
91
|
+
} else {
|
|
92
|
+
holder += m[1].replace(/-$/, '') + ' ' + m[2].replace(/d/, '.') + ',';
|
|
93
|
+
}
|
|
94
|
+
if(cssVar) holder+=' var('+cssVar+')';
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
return holder.replace(/[,]$/, '');
|
|
98
|
+
}
|
|
99
|
+
const func: { [key: string]: string } = {
|
|
100
|
+
e: 'ease',
|
|
101
|
+
ease: 'ease',
|
|
102
|
+
linear: 'linear',
|
|
103
|
+
l: 'linear',
|
|
104
|
+
ei: 'ease-in',
|
|
105
|
+
'ease-in': 'ease-in',
|
|
106
|
+
eo: 'ease-out',
|
|
107
|
+
'ease-out': 'ease-out',
|
|
108
|
+
eio: 'ease-in-out',
|
|
109
|
+
'ease-in-out': 'ease-in-out',
|
|
110
|
+
ss: 'step-start',
|
|
111
|
+
'step-start': 'step-start',
|
|
112
|
+
se: 'step-end',
|
|
113
|
+
'step-end': 'step-end',
|
|
114
|
+
};
|
|
115
|
+
*/
|
package/lib/compilers/url.js
CHANGED
|
@@ -9,9 +9,10 @@ export default function url(data) {
|
|
|
9
9
|
holder += 'url' + each + ',';
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
-
// css
|
|
12
|
+
// css variable: url() can't contain var(), so the variable holds the whole url(...)
|
|
13
|
+
// (url(var(--x)) is rejected by the browser)
|
|
13
14
|
if (each.match(/^--[a-zA-Z]/)) {
|
|
14
|
-
holder += `
|
|
15
|
+
holder += `var(${each}),`;
|
|
15
16
|
return;
|
|
16
17
|
}
|
|
17
18
|
let dir = '';
|
|
@@ -30,10 +31,59 @@ export default function url(data) {
|
|
|
30
31
|
each = each
|
|
31
32
|
.replace(/^[-_]/, '')
|
|
32
33
|
.replace(new RegExp(divider, 'g'), '/')
|
|
33
|
-
.replace(/[\/]([a-
|
|
34
|
+
.replace(/[\/]([a-zA-Z0-9]+)$/, '.$1'); // PNG, JPG too
|
|
34
35
|
holder += "url('" + dir + each + "'),";
|
|
35
36
|
});
|
|
36
37
|
return holder.replace(/[,]$/, '').trim();
|
|
37
38
|
// note restriction not use folder with name that uses ../../also need to figure out for
|
|
38
39
|
// bg-url_3_path_to_folder-name_name_png--3_
|
|
39
40
|
}
|
|
41
|
+
/*
|
|
42
|
+
export default function url(data: string) {
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
// bg-url3-path-to-folder-png
|
|
47
|
+
// bg-url3_path_to-the_folder_name_png
|
|
48
|
+
let holder = '';
|
|
49
|
+
data.split(/__/).forEach((each) => {
|
|
50
|
+
each = each.replace(/^[-]?url/, '');
|
|
51
|
+
// match raw-css function
|
|
52
|
+
if(each.match(/^[(]/)){
|
|
53
|
+
holder+='url'+each+',';
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// css-var inside url
|
|
58
|
+
if(each.match(/^--[a-zA-Z]/)){
|
|
59
|
+
holder+= `url(var(${each})),`;
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
let dir: string = '';
|
|
63
|
+
if (each.match(/^[-]?[\d][-_]/)) {
|
|
64
|
+
const ndir = /^([0-9])[-_]/.exec(each);
|
|
65
|
+
if (ndir)
|
|
66
|
+
for (let i = 0; i < parseInt(ndir[1], 10); i++) {
|
|
67
|
+
dir += '../';
|
|
68
|
+
}
|
|
69
|
+
each = each.replace(/^[\d]/, '');
|
|
70
|
+
}
|
|
71
|
+
if (!/^[-_]/.test(each)) {
|
|
72
|
+
each = '-' + each;
|
|
73
|
+
}
|
|
74
|
+
const divider = each.slice(0, 1);
|
|
75
|
+
|
|
76
|
+
each = each
|
|
77
|
+
.replace(/^[-_]/, '')
|
|
78
|
+
.replace(new RegExp(divider, 'g'), '/')
|
|
79
|
+
.replace(/[\/]([a-z0-9]+)$/, '.$1');
|
|
80
|
+
|
|
81
|
+
holder += "url('" + dir + each + "'),";
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return holder.replace(/[,]$/, '').trim();
|
|
85
|
+
|
|
86
|
+
// note restriction not use folder with name that uses ../../also need to figure out for
|
|
87
|
+
// bg-url_3_path_to_folder-name_name_png--3_
|
|
88
|
+
}
|
|
89
|
+
*/
|
package/lib/config.d.ts
CHANGED
package/lib/config.js
CHANGED
|
@@ -2,38 +2,7 @@ import prebuild from "./prebuild.js";
|
|
|
2
2
|
import { cssVarWithDefault } from "./utils/helper.js";
|
|
3
3
|
import color from './compilers/color.js';
|
|
4
4
|
import length from './compilers/length.js';
|
|
5
|
-
const cssCustomCompilers = Object.assign(Object.assign({}, prebuild), {
|
|
6
|
-
// 'Button':{
|
|
7
|
-
// type:'group',
|
|
8
|
-
// compiler:(value,custom)=>{
|
|
9
|
-
// let stm='';
|
|
10
|
-
// const order=['color','background-color','border-color'];
|
|
11
|
-
// const values=value.replace(/^\(|\)$/g,'').split(',');
|
|
12
|
-
// values.forEach((e,i)=>{
|
|
13
|
-
// if(i<order.length){
|
|
14
|
-
// stm+=`${order[i]}:${color(e,custom)};`
|
|
15
|
-
// }
|
|
16
|
-
// });
|
|
17
|
-
// return stm;
|
|
18
|
-
// }
|
|
19
|
-
// options:{
|
|
20
|
-
// 'solid':'background-color:var(--main-color),color:var(--main-text-color,#fff)',
|
|
21
|
-
// 'outline':'--background-color:var(--outline-bg-color,transparent),--button-color:var(--main-color)',
|
|
22
|
-
// 'link':'background-color:var(--outline-bg-color,transparent),color:var(--main-color),border:none',
|
|
23
|
-
// 'ghost':'background:transparent',
|
|
24
|
-
// 'primary':'--button-main-color:var(--primary-color,),',
|
|
25
|
-
// 'success':'',
|
|
26
|
-
// 'error':'',
|
|
27
|
-
// 'warning':'',
|
|
28
|
-
// 'info':'',
|
|
29
|
-
// 'xs':'border-radius: 4px;padding: 0px 8px;font-size: 12px;height: 24px;line-height: 16px;gap: 4px;',
|
|
30
|
-
// 'sm':'border-radius: 4px;padding: 0px 12px;font-size: 14px;height: 32px;line-height: 20px;gap: 8px;',
|
|
31
|
-
// 'md':'border-radius: 4px;padding: 0px 15px;font-size: 15px;font-weight: 500;height: 35px;line-height: 1;',
|
|
32
|
-
// 'lg':'border-radius: 6px;padding: 0px 16px;font-size: 16px;height: 40px;line-height: 24px;gap: 12px;',
|
|
33
|
-
// 'lg':'border-radius: 6px; padding: 0px 24px;font-size: 18px;height: 48px;line-height: 26px;gap: 14px;',
|
|
34
|
-
// },
|
|
35
|
-
// },
|
|
36
|
-
'InsetRA': {
|
|
5
|
+
const cssCustomCompilers = Object.assign(Object.assign({}, prebuild), { 'InsetRA': {
|
|
37
6
|
type: 'group',
|
|
38
7
|
compiler: (value, custom) => {
|
|
39
8
|
// const val=value.replace(/^\(/,'').replace(/\)$/,'').trim();
|
|
@@ -752,42 +721,6 @@ const cssCustomCompilers = Object.assign(Object.assign({}, prebuild), {
|
|
|
752
721
|
},
|
|
753
722
|
},
|
|
754
723
|
// ---------------------x-custom-compiler
|
|
755
|
-
'x-row': {
|
|
756
|
-
type: 'group',
|
|
757
|
-
compiler: (value) => {
|
|
758
|
-
return `--x-row-gap:${value.trim() ? value.replace(/^-(\d)/, '$1') : '16px'};display:flex;flex-wrap:wrap;margin-left:calc(var(--x-row-gap,${value.replace(/^-(\d)/, '$1')}) * -0.5);margin-right:calc(var(--x-row-gap,${value.replace(/^-(\d)/, '$1')}) * -0.5);`;
|
|
759
|
-
},
|
|
760
|
-
groups: {
|
|
761
|
-
'xs': `--x-row-gap:4px;display:flex;flex-wrap:wrap;margin-left:calc(var(--x-row-gap,4px) * -0.5);margin-right:calc(var(--x-row-gap,4px) * -0.5);`,
|
|
762
|
-
'sm': `--x-row-gap:8px;display:flex;flex-wrap:wrap;margin-left:calc(var(--x-row-gap,8px) * -0.5);margin-right:calc(var(--x-row-gap,8px) * -0.5);`,
|
|
763
|
-
'md': `--x-row-gap:16px;display:flex;flex-wrap:wrap;margin-left:calc(var(--x-row-gap,16px) * -0.5);margin-right:calc(var(--x-row-gap,16px) * -0.5);`,
|
|
764
|
-
'lg': `--x-row-gap:24px;display:flex;flex-wrap:wrap;margin-left:calc(var(--x-row-gap,24px) * -0.5);margin-right:calc(var(--x-row-gap,24px) * -0.5);`,
|
|
765
|
-
'xl': `--x-row-gap:32px;display:flex;flex-wrap:wrap;margin-left:calc(var(--x-row-gap,32px) * -0.5);margin-right:calc(var(--x-row-gap,32px) * -0.5);`,
|
|
766
|
-
},
|
|
767
|
-
}, 'x-col': {
|
|
768
|
-
type: 'group',
|
|
769
|
-
compiler: (value) => {
|
|
770
|
-
return `--x-col-width:${value.replace(/^-(\d)/, '$1')};padding-left:calc(var(--x-row-gap,16px) * 0.5);padding-right:calc(var(--x-row-gap,16px) * 0.5);box-sizing:border-box;flex:0 0 var(--x-col-width,${value.replace(/^-(\d)/, '$1')});max-width:var(--x-col-width,${value.replace(/^-(\d)/, '$1')});`;
|
|
771
|
-
},
|
|
772
|
-
groups: {
|
|
773
|
-
'1': `padding-left:calc(var(--x-row-gap,16px) * 0.5);padding-right:calc(var(--x-row-gap,16px) * 0.5); box-sizing:border-box;flex:0 0 8.333%;max-width:8.333%;`,
|
|
774
|
-
'2': `padding-left:calc(var(--x-row-gap,16px) * 0.5);padding-right:calc(var(--x-row-gap,16px) * 0.5); box-sizing:border-box;flex:0 0 16.6667%;max-width:16.6667%;`,
|
|
775
|
-
'3': `padding-left:calc(var(--x-row-gap,16px) * 0.5);padding-right:calc(var(--x-row-gap,16px) * 0.5); box-sizing:border-box;flex:0 0 25%;max-width:25%;`,
|
|
776
|
-
'4': `padding-left:calc(var(--x-row-gap,16px) * 0.5);padding-right:calc(var(--x-row-gap,16px) * 0.5); box-sizing:border-box;flex:0 0 33.3333%;max-width:33.3333%;`,
|
|
777
|
-
'5': `padding-left:calc(var(--x-row-gap,16px) * 0.5);padding-right:calc(var(--x-row-gap,16px) * 0.5); box-sizing:border-box;flex:0 0 41.6667%;max-width:41.6667%;`,
|
|
778
|
-
'6': `padding-left:calc(var(--x-row-gap,16px) * 0.5);padding-right:calc(var(--x-row-gap,16px) * 0.5); box-sizing:border-box;flex:0 0 50%;max-width:50%;`,
|
|
779
|
-
'7': `padding-left:calc(var(--x-row-gap,16px) * 0.5);padding-right:calc(var(--x-row-gap,16px) * 0.5); box-sizing:border-box;flex:0 0 58.3333%;max-width:58.3333%;`,
|
|
780
|
-
'8': `padding-left:calc(var(--x-row-gap,16px) * 0.5);padding-right:calc(var(--x-row-gap,16px) * 0.5); box-sizing:border-box;flex:0 0 66.6667%;max-width:66.6667%;`,
|
|
781
|
-
'9': `padding-left:calc(var(--x-row-gap,16px) * 0.5);padding-right:calc(var(--x-row-gap,16px) * 0.5); box-sizing:border-box;flex:0 0 75%;max-width:75%;`,
|
|
782
|
-
'10': `padding-left:calc(var(--x-row-gap,16px) * 0.5);padding-right:calc(var(--x-row-gap,16px) * 0.5); box-sizing:border-box;flex:0 0 83.3333%;max-width:83.3333%;`,
|
|
783
|
-
'11': `padding-left:calc(var(--x-row-gap,16px) * 0.5);padding-right:calc(var(--x-row-gap,16px) * 0.5); box-sizing:border-box;flex:0 0 91.6667%;max-width:91.6667%;`,
|
|
784
|
-
'12': `padding-left:calc(var(--x-row-gap,16px) * 0.5);padding-right:calc(var(--x-row-gap,16px) * 0.5); box-sizing:border-box;flex:0 0 100%;max-width:100%;`,
|
|
785
|
-
},
|
|
786
|
-
},
|
|
787
|
-
// 'x-col-responsive':{
|
|
788
|
-
// type:'statement',
|
|
789
|
-
// statement:`[]`,
|
|
790
|
-
// },
|
|
791
724
|
'x-square': {
|
|
792
725
|
type: 'group',
|
|
793
726
|
compiler: (value) => {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import styleToAliascss from "./utils/stylesToAliascss.js";
|
|
2
2
|
export declare const getCompiler: (property: string) => {
|
|
3
|
-
alias?: string
|
|
4
|
-
property?: string
|
|
5
|
-
test?: RegExp
|
|
6
|
-
type?: string
|
|
7
|
-
values?: string[]
|
|
3
|
+
alias?: string;
|
|
4
|
+
property?: string;
|
|
5
|
+
test?: RegExp;
|
|
6
|
+
type?: string;
|
|
7
|
+
values?: string[];
|
|
8
8
|
groups?: {
|
|
9
9
|
[key: string]: string;
|
|
10
|
-
}
|
|
11
|
-
compiler?: (
|
|
10
|
+
};
|
|
11
|
+
compiler?: (a: string, b: {
|
|
12
12
|
[key: string]: {
|
|
13
13
|
[key: string]: string;
|
|
14
14
|
};
|
|
15
|
-
}) => any
|
|
15
|
+
}) => any;
|
|
16
16
|
} | null;
|
|
17
17
|
export declare const main: {
|
|
18
18
|
[key: string]: any;
|
|
19
|
-
make: (a: string, b?: string
|
|
19
|
+
make: (a: string, b?: string, c?: boolean) => string;
|
|
20
20
|
group: (a: string, b: string) => string;
|
|
21
21
|
};
|
|
22
22
|
export declare const styleJSX: (str: string, bool?: boolean) => any;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default function main(config: {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
input: string | string[];
|
|
4
|
+
}): Promise<void>;
|
|
5
|
+
export declare function globalCSSCompiler(): Promise<void>;
|
|
6
|
+
export declare function compileFile(file: string, config: any, statementMaker: {
|
|
7
|
+
make: (a: string, b?: any, c?: any) => string;
|
|
8
|
+
group: (a: string, b: string) => string;
|
|
9
|
+
rawCSS?: string;
|
|
10
|
+
customGroupStatement?: string;
|
|
11
|
+
}, globalClassList: string[]): string[];
|
|
12
|
+
export declare function groupStatement(name: string, classNames: string, statementMaker: {
|
|
13
|
+
group: (a: string, b: string) => string;
|
|
14
|
+
}): string;
|
|
15
|
+
export declare function keyframesStatement(name: string, timeLine: string, statementMaker: {
|
|
16
|
+
make: (a: string, b?: string | null, c?: boolean) => string;
|
|
17
|
+
}): string;
|
|
18
|
+
export declare function createCSSFileByFile(file: string, bool?: boolean): Promise<void>;
|
|
19
|
+
export declare function postify(file: string, plugin: any[], minify?: boolean, sort?: "mobile-first" | "desktop-first"): Promise<void>;
|
|
20
|
+
export declare function writeStatementToFile(file: string, content: string, from?: string): void;
|
|
21
|
+
export declare function initialize(configFile: {
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}): void;
|
|
24
|
+
export declare function watch(config: {
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
input: string | string[];
|
|
27
|
+
}): void;
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import extractClassNamesFromFile from "./extractClassNamesFromFile.js";
|
|
11
|
+
import { compiler as statementMaker } from "../returnStatement-bk-291026.js";
|
|
12
|
+
import config from "../config.js";
|
|
13
|
+
import fs from "fs";
|
|
14
|
+
import fg from "fast-glob";
|
|
15
|
+
import path from "path";
|
|
16
|
+
import postcss from "postcss";
|
|
17
|
+
import postcssDiscardDuplicates from "postcss-discard-duplicates";
|
|
18
|
+
import cssnano from "cssnano";
|
|
19
|
+
import chokidar from "chokidar";
|
|
20
|
+
import sortMediaQueries from "postcss-sort-media-queries";
|
|
21
|
+
import { splitByCommaOutsideParens } from "../utils/helper.js";
|
|
22
|
+
const init = {
|
|
23
|
+
classList: [],
|
|
24
|
+
groups: [],
|
|
25
|
+
input: "",
|
|
26
|
+
output: "",
|
|
27
|
+
"--file": false,
|
|
28
|
+
statementMaker,
|
|
29
|
+
config,
|
|
30
|
+
"--module": false,
|
|
31
|
+
rawCSS: "",
|
|
32
|
+
layers: [],
|
|
33
|
+
initializedLayer: false,
|
|
34
|
+
customGroupStatement: "",
|
|
35
|
+
minify: false,
|
|
36
|
+
globPattern: "",
|
|
37
|
+
};
|
|
38
|
+
export default function main(config) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
initialize(config);
|
|
41
|
+
if (init.config.prefix)
|
|
42
|
+
init.statementMaker.prefix = init.config.prefix;
|
|
43
|
+
if (init.input && (init.output || init["--file"])) {
|
|
44
|
+
const input = fg.sync(init.input, { dot: true });
|
|
45
|
+
input.forEach((file) => {
|
|
46
|
+
createCSSFileByFile(file, true);
|
|
47
|
+
});
|
|
48
|
+
if (init.output) {
|
|
49
|
+
yield globalCSSCompiler();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
console.error("Please Provide input, output or set '--file' to true");
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
export function globalCSSCompiler() {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const classList = [];
|
|
60
|
+
if (init.globPattern && init.output) {
|
|
61
|
+
fs.truncateSync(init.output);
|
|
62
|
+
let basePreamble = "";
|
|
63
|
+
// 1. Layer declaration
|
|
64
|
+
if (Array.isArray(init.layers) && init.layers.length > 0) {
|
|
65
|
+
basePreamble += `@layer ${init.layers.join(", ")};\n\n`;
|
|
66
|
+
init.initializedLayer = true;
|
|
67
|
+
}
|
|
68
|
+
// 2. Custom CSS statements & group statements
|
|
69
|
+
if (init.rawCSS) {
|
|
70
|
+
basePreamble += `/* Start :-----------ACSS:From aliasCSSConfig.statement------------------------*/\n${init.rawCSS}\n/* End :-----------ACSS aliasCSSConfig.statement----------------------------*/\n\n`;
|
|
71
|
+
}
|
|
72
|
+
if (init.customGroupStatement) {
|
|
73
|
+
basePreamble += `/* Start :-----------ACSS:From aliasCSSConfig.group------------------------*/\n${init.customGroupStatement}\n/* End :-----------ACSS aliasCSSConfig.group----------------------------*/\n\n`;
|
|
74
|
+
}
|
|
75
|
+
if (basePreamble) {
|
|
76
|
+
fs.writeFileSync(init.output, basePreamble, { flag: "a+" });
|
|
77
|
+
}
|
|
78
|
+
// 3. Process matched files
|
|
79
|
+
const input = fg.sync(init.globPattern, { dot: true });
|
|
80
|
+
input.forEach((file) => {
|
|
81
|
+
const [gbContent] = compileFile(file, config, statementMaker, classList);
|
|
82
|
+
try {
|
|
83
|
+
fs.writeFileSync(init.output, `/* Start :-----------ACSS ${path.relative(".", file)}------------------------*/\n${gbContent}\n/* End :-----------ACSS ${path.relative(".", file)}----------------------------*/\n\n`, { flag: "a+" });
|
|
84
|
+
console.log("AliasCSS compiled", path.relative(".", file), "to main css file :" + init.output);
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
console.log('\x1b[31m', "Couldn't able to append/create to main css file :" + init.output);
|
|
88
|
+
console.log(error);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
yield postify(init.output, [postcssDiscardDuplicates], init.minify);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
console.error("Please Provide input, output or set '--file' to true");
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
export function compileFile(file, config, statementMaker, globalClassList) {
|
|
99
|
+
let [globalStatement, compiledStatement, moduleStatement] = ["", "", ""];
|
|
100
|
+
if (statementMaker.rawCSS) {
|
|
101
|
+
compiledStatement += `/* From:aliacss.config.statement */\n${statementMaker.rawCSS}\n/* -----End:aliacss.config.statement----- */\n\n`;
|
|
102
|
+
moduleStatement += `/* From:aliacss.config.statement */\n${statementMaker.rawCSS}\n/* ------End:aliacss.config.statement----- */\n\n`;
|
|
103
|
+
}
|
|
104
|
+
if (statementMaker.customGroupStatement) {
|
|
105
|
+
compiledStatement += `/* From:aliacss.config.group */\n${statementMaker.customGroupStatement}\n/* -----End:aliacss.config.group----- */\n\n`;
|
|
106
|
+
moduleStatement += `/* From:aliacss.config.group */\n${statementMaker.customGroupStatement}\n/* -----End:aliacss.config.group----- */\n\n`;
|
|
107
|
+
}
|
|
108
|
+
const [classList, groups, keyframe, rawCSSStatement] = extractClassNamesFromFile(file, config);
|
|
109
|
+
if (rawCSSStatement) {
|
|
110
|
+
globalStatement += rawCSSStatement + "\n";
|
|
111
|
+
compiledStatement += rawCSSStatement + "\n";
|
|
112
|
+
}
|
|
113
|
+
for (const key in groups) {
|
|
114
|
+
if (Object.prototype.hasOwnProperty.call(groups, key)) {
|
|
115
|
+
if (/^module=/.test(key)) {
|
|
116
|
+
moduleStatement += statementMaker.group(groups[key], key.replace(/module=/, "")) + "\n";
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
const gpStatement = statementMaker.group(groups[key], key);
|
|
120
|
+
globalStatement += gpStatement + "\n";
|
|
121
|
+
compiledStatement += gpStatement + "\n";
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
classList.forEach((e) => {
|
|
126
|
+
const statement = statementMaker.make(e);
|
|
127
|
+
if (statement) {
|
|
128
|
+
if (globalClassList.indexOf(e) === -1) {
|
|
129
|
+
globalStatement += statement + "\n";
|
|
130
|
+
globalClassList.push(e);
|
|
131
|
+
}
|
|
132
|
+
compiledStatement += statement + "\n";
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
for (const key in keyframe) {
|
|
136
|
+
if (Object.prototype.hasOwnProperty.call(keyframe, key)) {
|
|
137
|
+
const kfStatement = keyframesStatement(key, keyframe[key], statementMaker);
|
|
138
|
+
globalStatement += kfStatement + "\n";
|
|
139
|
+
compiledStatement += kfStatement + "\n";
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return [globalStatement, compiledStatement, moduleStatement];
|
|
143
|
+
}
|
|
144
|
+
export function groupStatement(name, classNames, statementMaker) {
|
|
145
|
+
return statementMaker.group(classNames, name) + "\n";
|
|
146
|
+
}
|
|
147
|
+
export function keyframesStatement(name, timeLine, statementMaker) {
|
|
148
|
+
let kfStatement = "@keyframes " + name + "{\n";
|
|
149
|
+
const returnPnV = (e) => e.map((i) => statementMaker.make(i, null, true)).join(";");
|
|
150
|
+
const split = timeLine.split(/\s+/);
|
|
151
|
+
split.forEach((each) => {
|
|
152
|
+
try {
|
|
153
|
+
const [at, pNv] = each.replace(/\]\[/, "]-[").replace("-", "=").split("=");
|
|
154
|
+
kfStatement += ` ${at.replace("@", "").replace(/:/g, ",").replace(/,/g, "%,").replace(/[\[|\]]/g, "")}% {${returnPnV(splitByCommaOutsideParens(pNv.replace(/^\[|\]$/g, "")))}}`;
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
console.error("Not a valid entry for AliasCSS keyframes processor : " + each, error);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
return kfStatement + "\n}\n";
|
|
161
|
+
}
|
|
162
|
+
export function createCSSFileByFile(file_1) {
|
|
163
|
+
return __awaiter(this, arguments, void 0, function* (file, bool = false) {
|
|
164
|
+
const [gbContent, content, module] = compileFile(file, config, statementMaker, init.classList);
|
|
165
|
+
if (init["--module"] && module.trim()) {
|
|
166
|
+
try {
|
|
167
|
+
fs.writeFileSync(file + ".module.css", module);
|
|
168
|
+
console.log("AliasCSS compiled", path.relative(".", file), "module Locally ");
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
console.log('\x1b[31m', "Couldn't able to append/create locally from " + file);
|
|
172
|
+
console.log(error);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (init["--file"]) {
|
|
176
|
+
try {
|
|
177
|
+
fs.writeFileSync(file + ".css", content);
|
|
178
|
+
yield postify(file + ".css", [postcssDiscardDuplicates], init.minify);
|
|
179
|
+
console.log("AliasCSS compiled", path.relative(".", file), "Locally");
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
console.log('\x1b[31m', "Couldn't able to append/create locally from " + file);
|
|
183
|
+
console.log(error);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
export function postify(file_1, plugin_1) {
|
|
189
|
+
return __awaiter(this, arguments, void 0, function* (file, plugin, minify = false, sort = "mobile-first") {
|
|
190
|
+
if (!fs.existsSync(file))
|
|
191
|
+
return;
|
|
192
|
+
const data = fs.readFileSync(file, "utf-8");
|
|
193
|
+
const plugins = [...plugin, sortMediaQueries({ sort })];
|
|
194
|
+
if (minify)
|
|
195
|
+
plugins.push(cssnano);
|
|
196
|
+
const result = yield postcss(plugins).process(data, { from: undefined });
|
|
197
|
+
fs.writeFileSync(file, result.css);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
export function writeStatementToFile(file, content, from) {
|
|
201
|
+
if (init.output) {
|
|
202
|
+
try {
|
|
203
|
+
fs.writeFileSync(init.output, `\n/* Start :-----------ACSS:From aliasCSSConfig.${from}------------------------*/\n${content}\n/* End :-----------ACSS aliasCSSConfig.${from}----------------------------*/\n`, { flag: "a+" });
|
|
204
|
+
console.log("AliasCSS compiled", `[aliasCSSConfig.${from}]`, "aliascss.config.js");
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
console.log('\x1b[31m', `Couldn't able to append/create [key:${from}] from alias.config.js`);
|
|
208
|
+
console.log(error);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
export function initialize(configFile) {
|
|
213
|
+
if (configFile.hasOwnProperty("input")) {
|
|
214
|
+
init.input = configFile.input;
|
|
215
|
+
init.globPattern = configFile.input;
|
|
216
|
+
}
|
|
217
|
+
if (configFile.hasOwnProperty("layers") && Array.isArray(configFile.layers)) {
|
|
218
|
+
init.layers = configFile.layers;
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
init.layers = config.layers;
|
|
222
|
+
}
|
|
223
|
+
if (configFile.hasOwnProperty("prefix")) {
|
|
224
|
+
init.config.prefix = configFile.prefix;
|
|
225
|
+
}
|
|
226
|
+
if (configFile.hasOwnProperty("output")) {
|
|
227
|
+
const op = configFile.output;
|
|
228
|
+
if (op.hasOwnProperty("location"))
|
|
229
|
+
init.output = op.location;
|
|
230
|
+
if (op.hasOwnProperty("--file") && op["--file"] === true)
|
|
231
|
+
init["--file"] = true;
|
|
232
|
+
}
|
|
233
|
+
if (configFile.hasOwnProperty("custom") && typeof configFile.custom === "object") {
|
|
234
|
+
Object.keys(configFile.custom).forEach((key) => {
|
|
235
|
+
init.statementMaker.addCustom(key, configFile.custom[key]);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
if (configFile.hasOwnProperty("prebuild")) {
|
|
239
|
+
init.statementMaker.prebuild(configFile.prebuild);
|
|
240
|
+
}
|
|
241
|
+
if (configFile.hasOwnProperty("ignore") && Array.isArray(configFile.ignore)) {
|
|
242
|
+
configFile.ignore.forEach((each) => init.config.ignore.push(each.trim()));
|
|
243
|
+
}
|
|
244
|
+
if (configFile.hasOwnProperty("--module") && configFile.hasOwnProperty("importModuleAs")) {
|
|
245
|
+
init["--module"] = true;
|
|
246
|
+
init.config.useCSSModule = true;
|
|
247
|
+
init.config.matchCSSModuleFunction = init.config.createCSSModuleRegex(configFile.importModuleAs);
|
|
248
|
+
}
|
|
249
|
+
if (configFile.hasOwnProperty("minify")) {
|
|
250
|
+
init.minify = configFile.minify;
|
|
251
|
+
}
|
|
252
|
+
if (configFile.hasOwnProperty("extractorFunction")) {
|
|
253
|
+
init.config.useExtractorFunction = configFile.extractorFunction.trim() ? true : false;
|
|
254
|
+
if (init.config.useExtractorFunction)
|
|
255
|
+
init.config.matchExtractorFunction = init.config.createExtractorRegex(configFile.extractorFunction);
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
init.config.useExtractorFunction = true;
|
|
259
|
+
init.config.matchExtractorFunction = init.config.createExtractorRegex("String");
|
|
260
|
+
}
|
|
261
|
+
if (configFile.hasOwnProperty("extend") && typeof configFile.extend === "object") {
|
|
262
|
+
init.statementMaker.extend(configFile.extend);
|
|
263
|
+
}
|
|
264
|
+
if (configFile.hasOwnProperty("useColon")) {
|
|
265
|
+
init.config.useColon = configFile.useColon;
|
|
266
|
+
}
|
|
267
|
+
if (configFile.hasOwnProperty("media") && typeof configFile.media === "object") {
|
|
268
|
+
init.statementMaker.addMedia(configFile.media);
|
|
269
|
+
}
|
|
270
|
+
if (configFile.hasOwnProperty("statement")) {
|
|
271
|
+
init.rawCSS = configFile.statement;
|
|
272
|
+
init.statementMaker.rawCSS = configFile.statement;
|
|
273
|
+
}
|
|
274
|
+
if (configFile.hasOwnProperty("group")) {
|
|
275
|
+
init.customGroupStatement = init.statementMaker.groupObj(configFile.group);
|
|
276
|
+
init.statementMaker.customGroupStatement = init.statementMaker.groupObj(configFile.group);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
export function watch(config) {
|
|
280
|
+
main(config);
|
|
281
|
+
const watcher = chokidar.watch(init.input, {
|
|
282
|
+
ignored: "*.css",
|
|
283
|
+
persistent: true,
|
|
284
|
+
});
|
|
285
|
+
const compileFile = (file) => __awaiter(this, void 0, void 0, function* () {
|
|
286
|
+
console.log(`--processing file : ${file}`);
|
|
287
|
+
yield createCSSFileByFile(file, true);
|
|
288
|
+
yield globalCSSCompiler();
|
|
289
|
+
console.log("Done! ");
|
|
290
|
+
});
|
|
291
|
+
const log = console.log.bind(console);
|
|
292
|
+
watcher
|
|
293
|
+
.on("add", (path) => log(`File ${path} has been added to watch`))
|
|
294
|
+
.on("change", (path) => compileFile(path))
|
|
295
|
+
.on("addDir", (path) => log(`Directory ${path} has been added`))
|
|
296
|
+
.on("unlinkDir", (path) => log(`Directory ${path} has been removed`))
|
|
297
|
+
.on("raw", (event, path, details) => {
|
|
298
|
+
if (event === "created" && details.type === "file") {
|
|
299
|
+
if (init.globPattern) {
|
|
300
|
+
const files = fg.sync(init.globPattern, { absolute: true });
|
|
301
|
+
if (files.indexOf(path) !== -1)
|
|
302
|
+
watcher.add(path);
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
watcher.add(path);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
}
|