aliascss 1.1.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/.prettierrc +5 -0
- package/LICENSE +21 -0
- package/README.md +544 -0
- package/READMEEdititng.md +615 -0
- package/aliascss.config.js +201 -0
- package/bin/aliascss.js +101 -0
- package/dist/aliascss.js +1 -0
- package/jestconfig.json +10 -0
- package/lib/build/index.d.ts +1 -0
- package/lib/build/index.js +63 -0
- package/lib/classPrinter.d.ts +6 -0
- package/lib/classPrinter.js +233 -0
- package/lib/compilers/border.d.ts +5 -0
- package/lib/compilers/border.js +50 -0
- package/lib/compilers/clipPath.d.ts +5 -0
- package/lib/compilers/clipPath.js +57 -0
- package/lib/compilers/color.d.ts +5 -0
- package/lib/compilers/color.js +61 -0
- package/lib/compilers/filter.d.ts +7 -0
- package/lib/compilers/filter.js +54 -0
- package/lib/compilers/font.d.ts +5 -0
- package/lib/compilers/font.js +19 -0
- package/lib/compilers/gradient.d.ts +5 -0
- package/lib/compilers/gradient.js +138 -0
- package/lib/compilers/length.d.ts +2 -0
- package/lib/compilers/length.js +10 -0
- package/lib/compilers/shadow.d.ts +5 -0
- package/lib/compilers/shadow.js +55 -0
- package/lib/compilers/stringAndContent.d.ts +6 -0
- package/lib/compilers/stringAndContent.js +23 -0
- package/lib/compilers/timingFunction.d.ts +5 -0
- package/lib/compilers/timingFunction.js +35 -0
- package/lib/compilers/transform.d.ts +2 -0
- package/lib/compilers/transform.js +117 -0
- package/lib/compilers/transition.d.ts +1 -0
- package/lib/compilers/transition.js +35 -0
- package/lib/compilers/url.d.ts +1 -0
- package/lib/compilers/url.js +33 -0
- package/lib/config.d.ts +20 -0
- package/lib/config.js +21 -0
- package/lib/css-properties-all.d.ts +16 -0
- package/lib/css-properties-all.js +2642 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +7 -0
- package/lib/node/compileFile.d.ts +25 -0
- package/lib/node/compileFile.js +337 -0
- package/lib/node/extractClassNamesFromFile.d.ts +18 -0
- package/lib/node/extractClassNamesFromFile.js +105 -0
- package/lib/prefix/PseudoPrefix.d.ts +7 -0
- package/lib/prefix/PseudoPrefix.js +145 -0
- package/lib/prefix/attribute-selector.d.ts +5 -0
- package/lib/prefix/attribute-selector.js +14 -0
- package/lib/prefix/colonToDefaultConversion.d.ts +1 -0
- package/lib/prefix/colonToDefaultConversion.js +3 -0
- package/lib/prefix/element-selector.d.ts +5 -0
- package/lib/prefix/element-selector.js +25 -0
- package/lib/prefix/extractMediaPrefix.d.ts +3 -0
- package/lib/prefix/extractMediaPrefix.js +12 -0
- package/lib/prefix/extractPrefix.d.ts +1 -0
- package/lib/prefix/extractPrefix.js +66 -0
- package/lib/prefix/pseudoSelector.d.ts +1 -0
- package/lib/prefix/pseudoSelector.js +48 -0
- package/lib/prefix/pseudoSelectorNew.d.ts +1 -0
- package/lib/prefix/pseudoSelectorNew.js +78 -0
- package/lib/prefix/responsive.d.ts +10 -0
- package/lib/prefix/responsive.js +26 -0
- package/lib/returnPropertyAndValue.d.ts +8 -0
- package/lib/returnPropertyAndValue.js +42 -0
- package/lib/returnStatement.d.ts +5 -0
- package/lib/returnStatement.js +189 -0
- package/lib/static/customColors.d.ts +3 -0
- package/lib/static/customColors.js +376 -0
- package/lib/static/customStaticClassNames.d.ts +3 -0
- package/lib/static/customStaticClassNames.js +132 -0
- package/lib/static/staticClassNamesAlias.d.ts +3 -0
- package/lib/static/staticClassNamesAlias.js +1300 -0
- package/lib/utils/createCompilerObj.d.ts +35 -0
- package/lib/utils/createCompilerObj.js +97 -0
- package/lib/utils/cssFunc.d.ts +1 -0
- package/lib/utils/cssFunc.js +27 -0
- package/package.json +64 -0
- package/ts.js +5 -0
- package/tsconfig.json +14 -0
- package/tslint.json +9 -0
- package/webpack.config.js +11 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const attribute = {
|
|
2
|
+
test: /^[-]?[\[][a-z0-9-_]+([~*$^]?[=][a-z0-9-_:/.]+)?[\]]/,
|
|
3
|
+
process(className) {
|
|
4
|
+
const match = className.match(this.test);
|
|
5
|
+
if (match) {
|
|
6
|
+
const attr = match[0];
|
|
7
|
+
if (attr) {
|
|
8
|
+
const result = attr.replace(/[=]([a-z0-9-_:/.]+)[\]]/, '="$1"]').replace(/^[-_]/, ""); // replace(/([\[|\]])/g,'\\$1').replace(/([=])/g,'\\$1');
|
|
9
|
+
return [className.replace(attr, ''), result];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export default attribute;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function colonConversion(data: string): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const element = {
|
|
2
|
+
test: /^_[_]?[A-Za-z0-9_\.]+(?=[_[-])/,
|
|
3
|
+
process(className) {
|
|
4
|
+
const match = className.match(this.test);
|
|
5
|
+
if (match) {
|
|
6
|
+
const alias = match[0];
|
|
7
|
+
if (alias) {
|
|
8
|
+
const result = alias
|
|
9
|
+
.replace('next', ' + ')
|
|
10
|
+
.replace('child', ' > ')
|
|
11
|
+
.replace('siblings', ' ~')
|
|
12
|
+
.replace(/____/g, ' ~ ')
|
|
13
|
+
.replace(/___/g, ' + ')
|
|
14
|
+
.replace(/__/g, ' > ')
|
|
15
|
+
.replace(/_/g, ' ')
|
|
16
|
+
.replace(/[\s]all/, ' * ')
|
|
17
|
+
.replace(/[\s](dot)/g, (e, a) => { return ' .' + a.toLowerCase(); })
|
|
18
|
+
// .replace(/[\s]([A-Z])/g, (e, a) => { return ' .' + a.toLowerCase();})
|
|
19
|
+
.replace(/[\s]+/g, " ").trim();
|
|
20
|
+
return [className.replace(alias, ''), ' ' + result];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export default element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export default function extractMediaPrefix(className, prefix, match, bool = false) {
|
|
2
|
+
var _a;
|
|
3
|
+
if (className.match(match)) {
|
|
4
|
+
const prefixMedia = (_a = className.match(match)) === null || _a === void 0 ? void 0 : _a[0];
|
|
5
|
+
if (prefixMedia) {
|
|
6
|
+
if (prefix.hasOwnProperty(prefixMedia)) {
|
|
7
|
+
return [prefix[prefixMedia], className.replace(prefixMedia, '')];
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return ['', className];
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function extractPrefix(className: string): string[];
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// import pseudoSelector from './selector.js'
|
|
2
|
+
import pseudoSelector from './pseudoSelectorNew.js';
|
|
3
|
+
import elementSelector from './element-selector.js';
|
|
4
|
+
import attribute from './attribute-selector.js';
|
|
5
|
+
export default function extractPrefix(className) {
|
|
6
|
+
let workingClassName = className;
|
|
7
|
+
let result = '';
|
|
8
|
+
let match = false;
|
|
9
|
+
do {
|
|
10
|
+
const matched = pseudoSelector(workingClassName);
|
|
11
|
+
if (matched) {
|
|
12
|
+
workingClassName = matched[0];
|
|
13
|
+
if (result.match(/:(not|where|has|is)[)]?$/)) {
|
|
14
|
+
const m = result.match(/:(not|where|has|is)([)])?$/);
|
|
15
|
+
if (m === null || m === void 0 ? void 0 : m[2]) {
|
|
16
|
+
result = result.replace(/\)$/, '') + `(${matched[1]}))`;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
result += `(${matched[1]})`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
result += matched[1];
|
|
24
|
+
}
|
|
25
|
+
match = true;
|
|
26
|
+
}
|
|
27
|
+
else if (elementSelector.test.test(workingClassName)) {
|
|
28
|
+
const [replacedClassName, selector] = elementSelector.process(workingClassName);
|
|
29
|
+
if (result.match(/:(not|where|has|is)[)]?$/)) {
|
|
30
|
+
const m = result.match(/:(not|where|has|is)([)])?$/);
|
|
31
|
+
if (m === null || m === void 0 ? void 0 : m[2]) {
|
|
32
|
+
result = result.replace(/\)$/, '') + `(${selector}))`;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
result += `(${selector})`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
result += selector;
|
|
40
|
+
}
|
|
41
|
+
workingClassName = replacedClassName;
|
|
42
|
+
match = true;
|
|
43
|
+
}
|
|
44
|
+
else if (attribute.test.test(workingClassName)) {
|
|
45
|
+
const [replacedClassName, selector] = attribute.process(workingClassName);
|
|
46
|
+
if (result.match(/:(not|where|has|is)[)]?$/)) {
|
|
47
|
+
const m = result.match(/:(not|where|has|is)([)])?$/);
|
|
48
|
+
if (m === null || m === void 0 ? void 0 : m[2]) {
|
|
49
|
+
result = result.replace(/\)$/, '') + `(${selector}))`;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
result += `(${selector})`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
result += selector;
|
|
57
|
+
}
|
|
58
|
+
workingClassName = replacedClassName;
|
|
59
|
+
match = true;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
match = false;
|
|
63
|
+
}
|
|
64
|
+
} while (match);
|
|
65
|
+
return [result, workingClassName];
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function PseudoEleState(data: string): string[] | null;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import prefix, { createRegexForPseudo } from './PseudoPrefix.js';
|
|
2
|
+
export default function PseudoEleState(data) {
|
|
3
|
+
const match = createRegexForPseudo(prefix);
|
|
4
|
+
if (!match.test(data))
|
|
5
|
+
return null;
|
|
6
|
+
// case 1. nth
|
|
7
|
+
if (/(^--nth(-child-|-last-child-|-last-of-type|-of-type-))([0-9]+[n]?)(?=[-|_])/.test(data)) {
|
|
8
|
+
const mch = data.match(/^(--nth(-child-|-last-child-|-last-of-type|-of-type-))([0-9]+[n]?)(?=[-|_])/);
|
|
9
|
+
const cn = (mch === null || mch === void 0 ? void 0 : mch[0]) ? data.replace(mch[0], '') : '';
|
|
10
|
+
const alias = (mch === null || mch === void 0 ? void 0 : mch[1]) ? prefix[mch[1].replace(/-$/, '')] : '';
|
|
11
|
+
const cont = mch === null || mch === void 0 ? void 0 : mch[3];
|
|
12
|
+
return [cn, `${alias}(${cont})`];
|
|
13
|
+
// return pseudoHandlerNthChild(data,/(^--nth(-child-|-last-child-|-last-of-type|-of-type-))([0-9]+[n]?)(?=[-|_])/)
|
|
14
|
+
}
|
|
15
|
+
else if (/^(-(nc|nlc|nlot|not)-)([a-z0-9]+)(?=[-|_])/.test(data)) {
|
|
16
|
+
const mch = data.match(/^(-(n|nc|nlc|nlot|not)-)([a-z0-9]+)(?=[-|_])/);
|
|
17
|
+
const cn = (mch === null || mch === void 0 ? void 0 : mch[0]) ? data.replace(mch[0], '') : '';
|
|
18
|
+
const alias = (mch === null || mch === void 0 ? void 0 : mch[1]) ? prefix[mch[1].replace(/-$/, '')] : '';
|
|
19
|
+
const cont = mch === null || mch === void 0 ? void 0 : mch[3];
|
|
20
|
+
return [cn, `${alias}(${cont})`];
|
|
21
|
+
}
|
|
22
|
+
else if (/(^-(-not-|-has-|-is-|-where-|n-|hs-|w-|is-)([a-z0-9\.]+)(?=[-|_]))/.test(data)) {
|
|
23
|
+
console.log("matched");
|
|
24
|
+
const mch = data.match(/(^-(-not-|-has-|-is-|-where-|n-|hs-|w-|is-)([a-z0-9\.]+)(?=[-|_]))/);
|
|
25
|
+
console.log(mch);
|
|
26
|
+
const cn = (mch === null || mch === void 0 ? void 0 : mch[1]) ? data.replace(mch[1], '') : '';
|
|
27
|
+
const alias = (mch === null || mch === void 0 ? void 0 : mch[2]) ? prefix['-' + mch[2].replace(/-$/, '')] : '';
|
|
28
|
+
const cont = mch === null || mch === void 0 ? void 0 : mch[3];
|
|
29
|
+
return [cn, `${alias}(${cont})`];
|
|
30
|
+
}
|
|
31
|
+
else if (/(^--lang-([a-z]+)(?=[-|_]))/.test(data)) {
|
|
32
|
+
const mch = data.match(/(^--lang-([a-z0-9]+)(?=[-|_]))/);
|
|
33
|
+
const cn = (mch === null || mch === void 0 ? void 0 : mch[1]) ? data.replace(mch[1], '') : '';
|
|
34
|
+
// const alias=mch?.[1]?prefix[mch[1].replace(/-$/,'')]:'';
|
|
35
|
+
const cont = mch === null || mch === void 0 ? void 0 : mch[2];
|
|
36
|
+
return [cn, `:lang(${cont})`];
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const alias = data.match(match);
|
|
40
|
+
if (alias) {
|
|
41
|
+
if (prefix.hasOwnProperty(alias[0])) {
|
|
42
|
+
return [data.replace(alias[0], ''), prefix[alias[0]]];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// return [data, ''];
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function PseudoEleStateNew(data: string): string[] | null;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import prefix, { createRegexForPseudo } from './PseudoPrefix.js';
|
|
2
|
+
import extractPrefix from './extractPrefix.js';
|
|
3
|
+
export default function PseudoEleStateNew(data) {
|
|
4
|
+
const match = createRegexForPseudo(prefix);
|
|
5
|
+
if (!match.test(data))
|
|
6
|
+
return null;
|
|
7
|
+
const matchAndFunc = [
|
|
8
|
+
{
|
|
9
|
+
match: /^-([-]?(not|has|is|where|n|hs|w))\((.+)\)/,
|
|
10
|
+
func(value) {
|
|
11
|
+
const matched = value.match(this.match);
|
|
12
|
+
const newData = matched === null || matched === void 0 ? void 0 : matched[3];
|
|
13
|
+
if (newData) {
|
|
14
|
+
const [result, className] = extractPrefix(newData + '-display-none');
|
|
15
|
+
console.log(newData, result, className);
|
|
16
|
+
return [value.replace(matched[0], ''), `${prefix['-' + matched[1]]}(${result})`];
|
|
17
|
+
}
|
|
18
|
+
return [value.replace((matched === null || matched === void 0 ? void 0 : matched[0]) ? matched[0] : '', ''), ''];
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
match: /^-([-]?n(th(-child|-last-child|-last-of-type|-of-type)|c|lc|lot|ot))\((.+)\)/,
|
|
23
|
+
func(value) {
|
|
24
|
+
const matched = value.match(this.match);
|
|
25
|
+
return [value.replace((matched === null || matched === void 0 ? void 0 : matched[0]) ? matched[0] : '', ''), `${prefix['-' + (matched === null || matched === void 0 ? void 0 : matched[1])]}(${matched === null || matched === void 0 ? void 0 : matched[4]})`];
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
// accept (acss-selector)
|
|
30
|
+
if (data.match(matchAndFunc[0].match)) {
|
|
31
|
+
return matchAndFunc[0].func(data);
|
|
32
|
+
}
|
|
33
|
+
if (data.match(matchAndFunc[1].match)) {
|
|
34
|
+
return matchAndFunc[1].func(data);
|
|
35
|
+
}
|
|
36
|
+
// case 1. nth
|
|
37
|
+
if (/(^--nth(-child-|-last-child-|-last-of-type|-of-type-))([0-9]+[n]?)(?=[-|_])/.test(data)) {
|
|
38
|
+
const mch = data.match(/^(--nth(-child-|-last-child-|-last-of-type|-of-type-))([0-9]+[n]?)(?=[-|_])/);
|
|
39
|
+
const cn = (mch === null || mch === void 0 ? void 0 : mch[0]) ? data.replace(mch[0], '') : '';
|
|
40
|
+
const alias = (mch === null || mch === void 0 ? void 0 : mch[1]) ? prefix[mch[1].replace(/-$/, '')] : '';
|
|
41
|
+
const cont = mch === null || mch === void 0 ? void 0 : mch[3];
|
|
42
|
+
return [cn, `${alias}(${cont})`];
|
|
43
|
+
// return pseudoHandlerNthChild(data,/(^--nth(-child-|-last-child-|-last-of-type|-of-type-))([0-9]+[n]?)(?=[-|_])/)
|
|
44
|
+
}
|
|
45
|
+
else if (/^(-(nc|nlc|nlot|not)-)([a-z0-9]+)(?=[-|_])/.test(data)) {
|
|
46
|
+
const mch = data.match(/^(-(n|nc|nlc|nlot|not)-)([a-z0-9]+)(?=[-|_])/);
|
|
47
|
+
const cn = (mch === null || mch === void 0 ? void 0 : mch[0]) ? data.replace(mch[0], '') : '';
|
|
48
|
+
const alias = (mch === null || mch === void 0 ? void 0 : mch[1]) ? prefix[mch[1].replace(/-$/, '')] : '';
|
|
49
|
+
const cont = mch === null || mch === void 0 ? void 0 : mch[3];
|
|
50
|
+
return [cn, `${alias}(${cont})`];
|
|
51
|
+
}
|
|
52
|
+
else if (/(^-(-not-|-has-|-is-|-where-|n-|hs-|w-|is-)([a-z0-9\.]+)(?=[-|_]))/.test(data)) {
|
|
53
|
+
console.log("matched");
|
|
54
|
+
const mch = data.match(/(^-(-not-|-has-|-is-|-where-|n-|hs-|w-|is-)([a-z0-9\.]+)(?=[-|_]))/);
|
|
55
|
+
console.log(mch);
|
|
56
|
+
const cn = (mch === null || mch === void 0 ? void 0 : mch[1]) ? data.replace(mch[1], '') : '';
|
|
57
|
+
const alias = (mch === null || mch === void 0 ? void 0 : mch[2]) ? prefix['-' + mch[2].replace(/-$/, '')] : '';
|
|
58
|
+
const cont = mch === null || mch === void 0 ? void 0 : mch[3];
|
|
59
|
+
return [cn, `${alias}(${cont})`];
|
|
60
|
+
}
|
|
61
|
+
else if (/(^--lang-([a-z]+)(?=[-|_]))/.test(data)) {
|
|
62
|
+
const mch = data.match(/(^--lang-([a-z0-9]+)(?=[-|_]))/);
|
|
63
|
+
const cn = (mch === null || mch === void 0 ? void 0 : mch[1]) ? data.replace(mch[1], '') : '';
|
|
64
|
+
// const alias=mch?.[1]?prefix[mch[1].replace(/-$/,'')]:'';
|
|
65
|
+
const cont = mch === null || mch === void 0 ? void 0 : mch[2];
|
|
66
|
+
return [cn, `:lang(${cont})`];
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const alias = data.match(match);
|
|
70
|
+
if (alias) {
|
|
71
|
+
if (prefix.hasOwnProperty(alias[0])) {
|
|
72
|
+
return [data.replace(alias[0], ''), prefix[alias[0]]];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// return [data, ''];
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const media = {
|
|
2
|
+
// test:/^(print|xs|sm|md|lg|xl|xxl|-xs|-sm|-md|-lg|-xl|-xxl|-2xl)(?=[-|_])/,
|
|
3
|
+
test: new RegExp("^(" + "print|xs|sm|md|lg|xl|xxl|-xs|-sm|-md|-lg|-xl|-xxl|-2xl" + ")(?=[-|_])"),
|
|
4
|
+
target: {
|
|
5
|
+
print: '@media print',
|
|
6
|
+
xs: '@media (max-width : 576px)',
|
|
7
|
+
sm: '@media (min-width : 576px)',
|
|
8
|
+
md: '@media (min-width : 768px)',
|
|
9
|
+
lg: '@media (min-width : 992px)',
|
|
10
|
+
xl: '@media (min-width : 1200px)',
|
|
11
|
+
xxl: '@media (min-width : 1408px)',
|
|
12
|
+
'2xl': '@media (min-width : 1408px)',
|
|
13
|
+
'-xs': '@media (min-width : 576px)',
|
|
14
|
+
'-sm': '@media (max-width : 576px)',
|
|
15
|
+
'-md': '@media (max-width : 768px)',
|
|
16
|
+
'-lg': '@media (max-width : 992px)',
|
|
17
|
+
'-xl': '@media (max-width : 1200px)',
|
|
18
|
+
'-xxl': '@media (max-width : 1408px)',
|
|
19
|
+
'-2xl': '@media (max-width : 1408px)',
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
export function createRegexForMedia(prefix) {
|
|
23
|
+
const prefixAlias = Object.keys(prefix).reduce((previous, current) => previous + "|" + current);
|
|
24
|
+
return new RegExp("^(" + prefixAlias + ")(?=[-|_])");
|
|
25
|
+
}
|
|
26
|
+
export default media;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export default function getPropertyAndValue(className: string, cssPropertiesWithAlias: {}, staticClassNames: {
|
|
2
|
+
[key: string]: string;
|
|
3
|
+
}, custom: {
|
|
4
|
+
[key: string]: {
|
|
5
|
+
[key: string]: string;
|
|
6
|
+
};
|
|
7
|
+
}, extractProperty: any, // (a:string,b:{[key:string]:Property})=>[Property,string],
|
|
8
|
+
bool?: boolean): string[] | null | {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export default function getPropertyAndValue(className, cssPropertiesWithAlias, staticClassNames, custom, extractProperty, // (a:string,b:{[key:string]:Property})=>[Property,string],
|
|
2
|
+
bool = false) {
|
|
3
|
+
// Case 1 StaticClassNames
|
|
4
|
+
if (staticClassNames.hasOwnProperty(className)) {
|
|
5
|
+
return staticClassNames[className];
|
|
6
|
+
}
|
|
7
|
+
const [property, propertyKey] = extractProperty(className, cssPropertiesWithAlias);
|
|
8
|
+
if (property) {
|
|
9
|
+
const prop = property.property ? property.property : propertyKey;
|
|
10
|
+
// Case 2: CSS Variables
|
|
11
|
+
if (/--var--/.test(className)) {
|
|
12
|
+
const splits = className.split(/--var--/);
|
|
13
|
+
if (cssPropertiesWithAlias.hasOwnProperty(splits[0])) {
|
|
14
|
+
return bool ? [prop, "var(--" + splits[1] + ')'] : prop + ": var(--" + splits[1] + ')';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
// case 3: CSS variable without --var keyword
|
|
18
|
+
const valuePortion = className.replace(propertyKey, '');
|
|
19
|
+
if (/^--[a-z]/.test(valuePortion)) {
|
|
20
|
+
return bool ? [prop, "var(" + valuePortion + ')'] : prop + ": var(" + valuePortion + ')';
|
|
21
|
+
}
|
|
22
|
+
if (property.hasOwnProperty('compiler') && typeof property.compiler === 'function') {
|
|
23
|
+
// const value=property.compiler(valuePortion.replace(/^-/,'') ,custom);
|
|
24
|
+
const value = property.compiler(valuePortion, custom);
|
|
25
|
+
if (value && value !== '-') {
|
|
26
|
+
const val = value.replace(/([-]?)([\d]|10|11|12)col/g, (m, p1, p2) => `${p1}${parseFloat(((100 / 12) * parseFloat(p2)).toFixed(6))}%`);
|
|
27
|
+
return bool ? [prop, val] : prop + ":" + val;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
console.log(`${className}: '${propertyKey}' unable to compile value:${className.replace(propertyKey, '')}`);
|
|
31
|
+
return bool ? [null, null] : null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
console.log("No Compiler found for:" + className);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
console.log(`${className}: is not valid AliasCSS class name`);
|
|
40
|
+
}
|
|
41
|
+
return bool ? [null, null] : null;
|
|
42
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import getPropertyAndValue from "./returnPropertyAndValue.js";
|
|
2
|
+
import { customStaticClassNames } from "./static/customStaticClassNames.js";
|
|
3
|
+
import media, { createRegexForMedia } from "./prefix/responsive.js";
|
|
4
|
+
import { customColors } from './static/customColors.js';
|
|
5
|
+
import extractPrefix from './prefix/extractPrefix.js';
|
|
6
|
+
import extractMediaPrefix from './prefix/extractMediaPrefix.js';
|
|
7
|
+
import { createCompilerObj, extractProperty } from "./utils/createCompilerObj.js";
|
|
8
|
+
import config from "./config.js";
|
|
9
|
+
import cssProps from "./css-properties-all.js";
|
|
10
|
+
import { staticClassNamesAlias } from "./static/staticClassNamesAlias.js";
|
|
11
|
+
const [staticClassNamesWithAlias, cssPropsWithAlias] = createCompilerObj(cssProps, config.globalValues);
|
|
12
|
+
export const compiler = {
|
|
13
|
+
// cache will cache propertyAndValue
|
|
14
|
+
cache: { propertyAndValue: Object.assign({}, customStaticClassNames) },
|
|
15
|
+
custom: Object.assign({ colors: customColors }),
|
|
16
|
+
mediaSelector: Object.assign({}, media.target),
|
|
17
|
+
mediaTest: null,
|
|
18
|
+
staticClassNames: Object.assign(Object.assign({}, staticClassNamesAlias), staticClassNamesWithAlias),
|
|
19
|
+
cssProps: Object.assign({}, cssPropsWithAlias),
|
|
20
|
+
prefix: null,
|
|
21
|
+
extend(data) {
|
|
22
|
+
Object.keys(data).forEach((key) => {
|
|
23
|
+
if (data[key].hasOwnProperty('extend')) {
|
|
24
|
+
if (cssProps.hasOwnProperty(data[key].extend)) {
|
|
25
|
+
Object.keys(cssProps[data[key].extend]).forEach((each) => {
|
|
26
|
+
if (each === 'values') {
|
|
27
|
+
data[key].values = [...cssProps[data[key].extend].values || [], ...data[key].values || []];
|
|
28
|
+
}
|
|
29
|
+
else if (each === 'compiler') {
|
|
30
|
+
data[key].compiler = cssProps[data[key].extend].compiler;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const [staticClassNames, compiler] = createCompilerObj(data, config.globalValues);
|
|
37
|
+
this.cssProps = Object.assign(Object.assign({}, this.cssProps), compiler);
|
|
38
|
+
this.staticClassNames = Object.assign(Object.assign({}, this.staticClassNames), staticClassNames);
|
|
39
|
+
},
|
|
40
|
+
// className as another-name, bool->only return property and value
|
|
41
|
+
make(className, as, bool) {
|
|
42
|
+
let unPrefixedClassName = className;
|
|
43
|
+
if (this.prefix && !className.match(new RegExp('^' + this.prefix + "[-]"))) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
else if (this.prefix) {
|
|
47
|
+
unPrefixedClassName = className.replace(new RegExp('^' + this.prefix + "[-]"), '');
|
|
48
|
+
}
|
|
49
|
+
if (!this.mediaTest)
|
|
50
|
+
this.mediaTest = createRegexForMedia(this.mediaSelector);
|
|
51
|
+
// 1. check and extract Media prefix and return className with prefix treatment,
|
|
52
|
+
let [media, workingClassName] = extractMediaPrefix(unPrefixedClassName, this.mediaSelector, this.mediaTest);
|
|
53
|
+
media = media;
|
|
54
|
+
let [elementAndPseudo, important] = ['', ''];
|
|
55
|
+
// workingClassName=workingClassName.replace(/[_][\.]([a-zA-Z])/g,(s,e)=>"_"+'ACSS').replace(/[.]/g,"d").replace(/[%]/g,'p')
|
|
56
|
+
// 2. Process --important flag
|
|
57
|
+
if (/(-i|--important)$/.test(className)) {
|
|
58
|
+
important = ' !important';
|
|
59
|
+
workingClassName = workingClassName.replace(/(-i|--important)$/, '');
|
|
60
|
+
}
|
|
61
|
+
// 3. process Pseudo State
|
|
62
|
+
const prefixPseudoElementAttribute = extractPrefix(workingClassName);
|
|
63
|
+
workingClassName = prefixPseudoElementAttribute[1];
|
|
64
|
+
elementAndPseudo = prefixPseudoElementAttribute[0];
|
|
65
|
+
// ---------------------------------------------------------------------
|
|
66
|
+
const pnv = workingClassName.replace(/^-/, '');
|
|
67
|
+
let result = '';
|
|
68
|
+
// x-class
|
|
69
|
+
if (/^(x-width|x-height)/.test(pnv)) {
|
|
70
|
+
const extract = getPropertyAndValue(pnv.replace('x-', ''), this.cssProps, this.staticClassNames, this.custom, extractProperty);
|
|
71
|
+
if (typeof extract === 'string') {
|
|
72
|
+
const [p, v] = extract.split(':');
|
|
73
|
+
if (p && v) {
|
|
74
|
+
result = `${p}:calc(${v} + var(--${p}-grow) - var(--${p}-shrink));--${p}:${v};--${p}-grow:0px;--${p}-shrink:0px`;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else if (this.cache.propertyAndValue.hasOwnProperty(pnv)) {
|
|
79
|
+
result = this.cache.propertyAndValue[pnv];
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
try {
|
|
83
|
+
result = getPropertyAndValue(pnv, this.cssProps, this.staticClassNames, this.custom, extractProperty);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
console.log(error);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (result) {
|
|
90
|
+
className = className.replace(/([$.%=\]\[@~:*#+\(\)\/^])/g, '\\$1');
|
|
91
|
+
if (bool === true)
|
|
92
|
+
return result;
|
|
93
|
+
this.cache.propertyAndValue[pnv] = result;
|
|
94
|
+
if (media) {
|
|
95
|
+
return `${media}{.${(as ? as : className) + elementAndPseudo}{${result}${important}}}`;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
return `.${(as ? as : className)}${elementAndPseudo}{${result}${important}}`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
console.log(`Unable to process ${className} [media:${media},pseudoSelector:${elementAndPseudo},imp:${important}]`);
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
group(str, as) {
|
|
106
|
+
let statement = '';
|
|
107
|
+
[...str.trim().split(/\s+/)].forEach((e) => {
|
|
108
|
+
const getEachClassNameCompiled = this.make(e, as);
|
|
109
|
+
if (getEachClassNameCompiled)
|
|
110
|
+
statement += getEachClassNameCompiled + ' \n';
|
|
111
|
+
});
|
|
112
|
+
return statement;
|
|
113
|
+
},
|
|
114
|
+
prebuild(a, b) {
|
|
115
|
+
if (typeof a === 'object') {
|
|
116
|
+
for (const key in a) {
|
|
117
|
+
if (a.hasOwnProperty(key))
|
|
118
|
+
this.cache.propertyAndValue[key] = a[key];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
if (a && b) {
|
|
123
|
+
this.cache.propertyAndValue[a] = b;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
groupForJs(str, bool) {
|
|
128
|
+
if (!str.trim())
|
|
129
|
+
return '';
|
|
130
|
+
const jsStyle = {};
|
|
131
|
+
const list = str.trim().split(/\s+/);
|
|
132
|
+
list.forEach((e) => {
|
|
133
|
+
let pNv = '';
|
|
134
|
+
if (this.cache.propertyAndValue.hasOwnProperty(e)) {
|
|
135
|
+
pNv = this.cache.propertyAndValue[e];
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
pNv = getPropertyAndValue(e, this.cssProps, this.staticClassNames, this.custom, extractProperty);
|
|
139
|
+
if (pNv)
|
|
140
|
+
this.cache.propertyAndValue[e] = pNv;
|
|
141
|
+
}
|
|
142
|
+
if (!pNv)
|
|
143
|
+
return '';
|
|
144
|
+
const result = pNv.split(':');
|
|
145
|
+
if (result.length === 2) {
|
|
146
|
+
const key = result[0].replace(/-([a-z])/g, (e, a) => {
|
|
147
|
+
return a.toUpperCase();
|
|
148
|
+
});
|
|
149
|
+
let value = bool === true ? result[1].replace(/px$/g, '') : result[1];
|
|
150
|
+
if (typeof value === 'string' && value.trim().match(/^[\d\.]+$/)) {
|
|
151
|
+
value = parseFloat(value.toString());
|
|
152
|
+
}
|
|
153
|
+
jsStyle[key] = value;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
return jsStyle;
|
|
157
|
+
},
|
|
158
|
+
// for config
|
|
159
|
+
groupObj(obj) {
|
|
160
|
+
if (typeof obj !== 'object')
|
|
161
|
+
return false;
|
|
162
|
+
let statement = '';
|
|
163
|
+
for (const key in obj) {
|
|
164
|
+
if (obj.hasOwnProperty(key)) {
|
|
165
|
+
const result = this.group(obj[key], key);
|
|
166
|
+
if (result) {
|
|
167
|
+
statement += result + '\n';
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return statement;
|
|
172
|
+
},
|
|
173
|
+
addCustom(name, obj) {
|
|
174
|
+
name = (name === 'color' ? 'colors' : name);
|
|
175
|
+
if (typeof obj === 'object') {
|
|
176
|
+
if (!this.custom[name])
|
|
177
|
+
this.custom[name] = {};
|
|
178
|
+
for (const key in obj) {
|
|
179
|
+
if (obj.hasOwnProperty(key))
|
|
180
|
+
this.custom[name][key] = obj[key];
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
addMedia(obj) {
|
|
185
|
+
this.mediaSelector = Object.assign(Object.assign({}, this.mediaSelector), obj);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
// compiler.staticClassNames={...helper().generateStaticClassNames(compiler.cssProps,config['css-global-values'])};
|
|
189
|
+
// compiler.addCustom('color',customColors)
|