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,233 @@
|
|
|
1
|
+
import { compiler as statementMaker } from './returnStatement.js';
|
|
2
|
+
export default statementMaker;
|
|
3
|
+
export let classPrinter = {
|
|
4
|
+
invalidLists: [],
|
|
5
|
+
classLists: [],
|
|
6
|
+
styleTagExists: false,
|
|
7
|
+
customCheck: false,
|
|
8
|
+
useColon: true,
|
|
9
|
+
styleTag: null,
|
|
10
|
+
createStyleTag() {
|
|
11
|
+
if (this.styleTagExists === true) {
|
|
12
|
+
return this.styleTag;
|
|
13
|
+
}
|
|
14
|
+
const styleTag = document.createElement('style');
|
|
15
|
+
styleTag.id = 'styleAlias';
|
|
16
|
+
document.getElementsByTagName('head')[0].appendChild(styleTag);
|
|
17
|
+
this.styleTag = styleTag;
|
|
18
|
+
this.styleTagExists = true;
|
|
19
|
+
return styleTag;
|
|
20
|
+
},
|
|
21
|
+
// you can always append a class if you like modify the look here if you want
|
|
22
|
+
appendToStyleTag(classStatement) {
|
|
23
|
+
const createNewClass = document.createTextNode(classStatement);
|
|
24
|
+
this.createStyleTag().appendChild(createNewClass);
|
|
25
|
+
},
|
|
26
|
+
// compile dom stylesheet
|
|
27
|
+
// show current style statement
|
|
28
|
+
compile() {
|
|
29
|
+
const classes = document.getElementById('styleAlias');
|
|
30
|
+
if (classes) {
|
|
31
|
+
const prettyPrint = classes.innerHTML
|
|
32
|
+
.replace(/\}/g, '</br>}</br>')
|
|
33
|
+
.replace(/\{/g, '{</br> ');
|
|
34
|
+
document.write(prettyPrint);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
console.warn('There is not ACSS used in this document!!');
|
|
38
|
+
alert('Could not found acss statements in this Document!');
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
// print className of el to style tag; gets statement from statementMaker.make(eachClass);
|
|
42
|
+
print(el) {
|
|
43
|
+
// initialize class or acss-class value container
|
|
44
|
+
let attrValue = '';
|
|
45
|
+
const testRegExp = this.useColon ? /class[-_:]/ : /class[-_]/;
|
|
46
|
+
const testRegExpKF = this.useColon ? /keyframes[-_:]/ : /keyframes[-_]/;
|
|
47
|
+
// if class
|
|
48
|
+
if (el.getAttribute('class'))
|
|
49
|
+
attrValue += ' ' + el.getAttribute('class');
|
|
50
|
+
// if acss-class
|
|
51
|
+
if (el.getAttribute('acss-class'))
|
|
52
|
+
attrValue += ' ' + el.getAttribute('acss-class');
|
|
53
|
+
// new Update
|
|
54
|
+
[...el.attributes].map((each) => {
|
|
55
|
+
// ------------
|
|
56
|
+
if (testRegExp.test(each.name)) {
|
|
57
|
+
let value = each.value;
|
|
58
|
+
let group = each.name.replace(testRegExp, '');
|
|
59
|
+
const match = group.match(/\[(.)+\]/);
|
|
60
|
+
if (match) {
|
|
61
|
+
group = group.replace(match[0], '');
|
|
62
|
+
value = value.trim().split(/\s+/).map(e => match[0].replace(/^\[/, '').replace(/\]$/, '') + (/^[_-]/.test(e) ? '' : '-') + e).join(" ");
|
|
63
|
+
}
|
|
64
|
+
const result = statementMaker.group(value, group);
|
|
65
|
+
if (result) {
|
|
66
|
+
this.appendToStyleTag(result);
|
|
67
|
+
// return true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// -------
|
|
71
|
+
// if( testRegExp.test(each.name)){
|
|
72
|
+
// const result = statementMaker.group(each.value, each.name.replace(testRegExp,''));
|
|
73
|
+
// if (result) {
|
|
74
|
+
// this.appendToStyleTag(result);
|
|
75
|
+
// // return true;
|
|
76
|
+
// }
|
|
77
|
+
// }
|
|
78
|
+
if (testRegExpKF.test(each.name)) {
|
|
79
|
+
const key = each.name.replace(testRegExpKF, '');
|
|
80
|
+
let kfStatement = '@keyframes ' + key + "{\n";
|
|
81
|
+
const split = each.value.trim().split(/\s+/);
|
|
82
|
+
split.forEach((each) => {
|
|
83
|
+
try {
|
|
84
|
+
const [at, pNv] = each.replace("-", "=").split("=");
|
|
85
|
+
const result = statementMaker.make(pNv, undefined, true);
|
|
86
|
+
kfStatement += ` ${at.replace('@', '').replace(/:/g, ',').replace(/,/g, "%,").replace(/[\[|\]]/g, '')}% {${result ? result : ''}}`;
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
console.log('invalid Entry for AliasCSS keyframes processor : ' + each, error);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
this.appendToStyleTag(kfStatement + "\n}");
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
// if has value to process
|
|
96
|
+
if (!attrValue.trim())
|
|
97
|
+
return;
|
|
98
|
+
// has-test-group(for live update only)
|
|
99
|
+
if (el.getAttribute('acss-group-test')) {
|
|
100
|
+
const result = statementMaker.group(attrValue, el.getAttribute('acss-group-test') || '');
|
|
101
|
+
const styleTag = document.querySelector('style#' + el.getAttribute('acss-group-test'));
|
|
102
|
+
if (result) {
|
|
103
|
+
if (styleTag) {
|
|
104
|
+
styleTag.innerHTML = '';
|
|
105
|
+
const createNewGroup = document.createTextNode(result);
|
|
106
|
+
styleTag.appendChild(createNewGroup);
|
|
107
|
+
// return true;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
const styleTag = document.createElement('style');
|
|
111
|
+
styleTag.id = el.getAttribute('acss-group-test');
|
|
112
|
+
document.getElementsByTagName('head')[0].appendChild(styleTag);
|
|
113
|
+
const createNewGroup = document.createTextNode(result);
|
|
114
|
+
styleTag.appendChild(createNewGroup);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// -----------------------end of for live update
|
|
119
|
+
// get class and trim out white spaces
|
|
120
|
+
const tmpClassList = attrValue.trim().split(/\s+/);
|
|
121
|
+
// looping class
|
|
122
|
+
tmpClassList.forEach((eachClass) => {
|
|
123
|
+
// escape repeated class name
|
|
124
|
+
if (this.classLists.indexOf(eachClass) === -1 && this.invalidLists.indexOf(eachClass) === -1) {
|
|
125
|
+
// add to classlist for reference
|
|
126
|
+
this.classLists.push(eachClass);
|
|
127
|
+
// var result=compiler.main(eachClass);
|
|
128
|
+
const result = statementMaker.make(eachClass);
|
|
129
|
+
// console.log(result);
|
|
130
|
+
if (result) {
|
|
131
|
+
this.appendToStyleTag(result);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
// not a valid ACSS classNames
|
|
135
|
+
this.invalidLists.push(eachClass);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}, // end-of-main
|
|
140
|
+
// returns css statement from current element
|
|
141
|
+
compileElement(el, list = []) {
|
|
142
|
+
const classList = list;
|
|
143
|
+
let statement = ' ';
|
|
144
|
+
// initialize class or acss-class value container
|
|
145
|
+
let attrValue = '';
|
|
146
|
+
const testRegExp = this.useColon ? /class[-_:]/ : /class[-_]/;
|
|
147
|
+
// matchRegExp:/(?:(class|className|class[-_][\w-\[\]=_]+))=[\s*]?(?:["']\W+\s*(?:\w+)\()?["']([^'"]+)['"]/,
|
|
148
|
+
// matchRegExpWithColon:/(?:(class|className|class[-_:][\w-\[\]=_]+))=[\s*]?(?:["']\W+\s*(?:\w+)\()?["']([^'"]+)['"]/,
|
|
149
|
+
// if class
|
|
150
|
+
if (el.getAttribute('class'))
|
|
151
|
+
attrValue += ' ' + el.getAttribute('class');
|
|
152
|
+
// New update 2023-aug-03
|
|
153
|
+
[...el.attributes].map((each) => {
|
|
154
|
+
if (testRegExp.test(each.name)) {
|
|
155
|
+
let value = each.value;
|
|
156
|
+
let group = each.name.replace(testRegExp, '');
|
|
157
|
+
const match = group.match(/\[(.)+\]/);
|
|
158
|
+
if (match) {
|
|
159
|
+
group = group.replace(match[0], '');
|
|
160
|
+
value = value.trim().split(/\s+/).map(e => match[0].replace(/^\[/, '').replace(/\]$/, '') + (/^[_-]/.test(e) ? '' : '-') + e).join(" ");
|
|
161
|
+
}
|
|
162
|
+
const result = statementMaker.group(value, group);
|
|
163
|
+
if (result) {
|
|
164
|
+
this.appendToStyleTag(result);
|
|
165
|
+
// return true;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
// if acss-class
|
|
170
|
+
if (el.getAttribute('acss-class'))
|
|
171
|
+
attrValue += ' ' + el.getAttribute('acss-class');
|
|
172
|
+
// if has value to process
|
|
173
|
+
if (!attrValue.trim())
|
|
174
|
+
return;
|
|
175
|
+
// get class and trim out whitespace
|
|
176
|
+
const tmpClassList = attrValue.trim().split(/\s+/);
|
|
177
|
+
// looping class
|
|
178
|
+
tmpClassList.forEach((eachClass) => {
|
|
179
|
+
// escape repeated className
|
|
180
|
+
if (classList.indexOf(eachClass) === -1) {
|
|
181
|
+
classList.push(eachClass);
|
|
182
|
+
// var result=compiler.main(eachClass);
|
|
183
|
+
const result = statementMaker.make(eachClass);
|
|
184
|
+
// console.log(result);
|
|
185
|
+
if (result) {
|
|
186
|
+
statement += result + ' ';
|
|
187
|
+
// this.appendToStyleTag(result);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
// not a valid ACSS classNames
|
|
191
|
+
console.log('Not a valid Aliascss class name:' + eachClass);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
return statement;
|
|
196
|
+
},
|
|
197
|
+
// returns css statement from given element and child
|
|
198
|
+
returnStatement($el) {
|
|
199
|
+
let statement = '';
|
|
200
|
+
const classList = [];
|
|
201
|
+
const processOuterHtml = this.compileElement($el, classList);
|
|
202
|
+
statement += processOuterHtml ? processOuterHtml : '';
|
|
203
|
+
// <template> element
|
|
204
|
+
Array.prototype.forEach.call($el.querySelectorAll('template'), (template) => {
|
|
205
|
+
Array.prototype.forEach.call(template.content.querySelectorAll('[class],[acss-class]'), (e) => {
|
|
206
|
+
const result = this.compileElement(e, classList);
|
|
207
|
+
statement += result ? result : '';
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
// <html>
|
|
211
|
+
Array.prototype.forEach.call($el.querySelectorAll('[class],[acss-class]'), (e) => {
|
|
212
|
+
const result = this.compileElement(e, classList);
|
|
213
|
+
statement += result ? result : '';
|
|
214
|
+
});
|
|
215
|
+
return statement;
|
|
216
|
+
},
|
|
217
|
+
run(el) {
|
|
218
|
+
// const event = new Event('acss:init');
|
|
219
|
+
const $root = el || document;
|
|
220
|
+
// $root.dispatchEvent(event);
|
|
221
|
+
$root.dispatchEvent(new CustomEvent('acss:init', { bubbles: true, detail: { aliascss: this } }));
|
|
222
|
+
// <template> element
|
|
223
|
+
Array.prototype.forEach.call($root.querySelectorAll('template'), (template) => {
|
|
224
|
+
Array.prototype.forEach.call(template.content.querySelectorAll('[class],[acss-class]'), (e) => {
|
|
225
|
+
this.print(e);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
// <html>
|
|
229
|
+
Array.prototype.forEach.call($root.querySelectorAll('[class],[acss-class]'), (e) => {
|
|
230
|
+
this.print(e);
|
|
231
|
+
});
|
|
232
|
+
},
|
|
233
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import color from './color.js';
|
|
2
|
+
export default function border(data, custom) {
|
|
3
|
+
// let result='';
|
|
4
|
+
const styleRegex = /-(none|n|hidden|h|dotted|dt|dashed|ds|solid|s|double|db|groove|g|ridge|r|inset|i|outset|o)(?:[^\w]|$)/;
|
|
5
|
+
const widthRegex = /[-]?([0-9]+[d/.]?[0-9]*(px|em|fr|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|p))/;
|
|
6
|
+
let [s, l, c] = ['', '', ''];
|
|
7
|
+
// Style
|
|
8
|
+
if (styleRegex.test(data)) {
|
|
9
|
+
const m = data.match(styleRegex);
|
|
10
|
+
s = m ? style[m[1]] : '';
|
|
11
|
+
data = m ? data.replace(m[0], '') : data;
|
|
12
|
+
}
|
|
13
|
+
// width
|
|
14
|
+
if (/-(thick|medium|thin)/.test(data)) {
|
|
15
|
+
const m = data.match(/-(thick|medium|thin)/);
|
|
16
|
+
l = m ? m[1] : '';
|
|
17
|
+
data = m ? data.replace(m[0], '') : data;
|
|
18
|
+
}
|
|
19
|
+
else if (widthRegex.test(data)) {
|
|
20
|
+
const m = data.match(widthRegex);
|
|
21
|
+
l = m ? m[1].replace(/p[\s]?$/, '%').replace(/(\d)d(\d)/, '$1.$2') : '';
|
|
22
|
+
data = m ? data.replace(m[0], '') : data;
|
|
23
|
+
}
|
|
24
|
+
if (data) {
|
|
25
|
+
c = color(data, custom);
|
|
26
|
+
}
|
|
27
|
+
return `${l ? l : ''} ${s ? s : ''} ${c ? c : ''}`.trim();
|
|
28
|
+
}
|
|
29
|
+
const style = {
|
|
30
|
+
n: 'none',
|
|
31
|
+
none: 'none',
|
|
32
|
+
s: 'solid',
|
|
33
|
+
solid: 'solid',
|
|
34
|
+
r: 'ridge',
|
|
35
|
+
ridge: 'ridge',
|
|
36
|
+
o: 'outset',
|
|
37
|
+
outset: 'outset',
|
|
38
|
+
i: 'inset',
|
|
39
|
+
inset: 'inset',
|
|
40
|
+
h: 'hidden',
|
|
41
|
+
hidden: 'hidden',
|
|
42
|
+
g: 'groove',
|
|
43
|
+
groove: 'groove',
|
|
44
|
+
db: 'double',
|
|
45
|
+
double: 'double',
|
|
46
|
+
dotted: 'dotted',
|
|
47
|
+
dt: 'dotted',
|
|
48
|
+
ds: 'dashed',
|
|
49
|
+
dashed: 'dashed',
|
|
50
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export default function clipPath(data, custom) {
|
|
2
|
+
const valuePortion = data.replace(/^-/, '') || '';
|
|
3
|
+
// const match = /^(path|pa|circle|c|inset|i|polygon|p|ellipse|e|xywh|rect|r)[-]?[\d]/;
|
|
4
|
+
const match = /^(path|pa|circle|c|inset|i|polygon|p|ellipse|e|xywh|rect|r)[-]?([\d]|-)/;
|
|
5
|
+
let shape = null;
|
|
6
|
+
let content = '';
|
|
7
|
+
const shapes = {
|
|
8
|
+
circle: 'circle',
|
|
9
|
+
c: 'circle',
|
|
10
|
+
inset: 'inset',
|
|
11
|
+
i: 'inset',
|
|
12
|
+
ellipse: 'ellipse',
|
|
13
|
+
e: 'ellipse',
|
|
14
|
+
polygon: 'polygon',
|
|
15
|
+
p: 'polygon',
|
|
16
|
+
rect: 'rect',
|
|
17
|
+
r: 'rect',
|
|
18
|
+
xywh: 'xywh',
|
|
19
|
+
url: 'url',
|
|
20
|
+
u: 'url',
|
|
21
|
+
path: 'path',
|
|
22
|
+
pa: 'path'
|
|
23
|
+
};
|
|
24
|
+
if (valuePortion.match(/^(url|u)/)) {
|
|
25
|
+
shape = 'url';
|
|
26
|
+
if (valuePortion.replace(/url|u/, '').match(/^--[a-zA-Z]/)) {
|
|
27
|
+
content = `var(${valuePortion.replace(/url|u/, '')})`;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
content = '#' + valuePortion.replace(/url|u/, '').replace(/^-/, '');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else if (valuePortion.match(match)) {
|
|
34
|
+
const extractShape = valuePortion.match(match);
|
|
35
|
+
if (extractShape) {
|
|
36
|
+
shape = shapes[extractShape[1]];
|
|
37
|
+
if (valuePortion.replace(extractShape[1], '').match(/^--[a-zA-z]/)) {
|
|
38
|
+
content = `var(${valuePortion.replace(extractShape[1], '')})`;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
content = valuePortion
|
|
42
|
+
.replace(extractShape[1], '').replace(/-0-/g, '-0px-')
|
|
43
|
+
.replace(/(px|em|p|ex|ch|rem|vw|fr|vh|vmin|vmax|cm|mm|in|pt|pc|cv)/g, '$1 ')
|
|
44
|
+
.replace(/p[\s]|p(,)/g, '%$1 ')
|
|
45
|
+
.replace(/_/g, ', ')
|
|
46
|
+
.replace('-at', ' at ').replace(/(\d)d(\d)/g, '$1.$2')
|
|
47
|
+
.replace('-round', ' round ').replace(/-([0-9][d/.]?[0-9]*)/g, '$1').replace(/[\s][0]px[\s]/g, ' 0 ')
|
|
48
|
+
.replace(/^0px[\s]/, '0 ');
|
|
49
|
+
}
|
|
50
|
+
// content=length(valuePortion.replace(extractShape,''));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
return shape + '(' + content + ')';
|
|
57
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// custom.color will be provided {primary:'#2d3f3e....}
|
|
2
|
+
export default function color(color, custom) {
|
|
3
|
+
if (color.match(/^--[a-zA-z]/))
|
|
4
|
+
return `var(${color})`;
|
|
5
|
+
color = color.replace(/^[-]/, '');
|
|
6
|
+
if (custom.hasOwnProperty('colors') && typeof custom.colors === 'object') {
|
|
7
|
+
if (custom.colors.hasOwnProperty(color))
|
|
8
|
+
return custom.colors[color];
|
|
9
|
+
}
|
|
10
|
+
// hexadecimal =+ alpha 00-ff
|
|
11
|
+
if (/^[0-9a-fA-F]{3,8}$/.test(color)) {
|
|
12
|
+
return `#${color}`;
|
|
13
|
+
// Name
|
|
14
|
+
}
|
|
15
|
+
else if (/^[a-zA-Z]+$/.test(color)) {
|
|
16
|
+
return color;
|
|
17
|
+
// rgb/a in number
|
|
18
|
+
}
|
|
19
|
+
else if (/^[0-9]{9}/.test(color)) {
|
|
20
|
+
if (color.length === 9)
|
|
21
|
+
return `rgb(${color.replace(/([\d]{3})([\d]{3})([\d]{3})/, '$1,$2,$3')})`;
|
|
22
|
+
else
|
|
23
|
+
return `rgba(${color
|
|
24
|
+
.replace(/([\d]{3})([\d]{3})([\d]{3})([\d]+)/, '$1,$2,$3,$4')
|
|
25
|
+
.replace('d', '.')
|
|
26
|
+
.replace('p', '%')})`;
|
|
27
|
+
}
|
|
28
|
+
else if (/^([\d]{3})([\d]{1,3}p)([\d]{1,3}p)/.test(color)) {
|
|
29
|
+
if (/^([\d]{3})([\d]{1,3}p)([\d]{1,3}p)$/.test(color))
|
|
30
|
+
return 'hsl(' + color.replace(/^([\d]{1,3})([\d]{1,3}p)([\d]{1,3}p)/, '$1,$2,$3').replace(/p/g, '%') + ')';
|
|
31
|
+
else
|
|
32
|
+
return ('hsla(' +
|
|
33
|
+
color
|
|
34
|
+
.replace(/^([\d]{1,3})([\d]{1,3}p)([\d]{1,3}p)([\d]+)/, '$1,$2,$3,$4')
|
|
35
|
+
.replace('d', '.')
|
|
36
|
+
.replace(/p/g, '%') +
|
|
37
|
+
')');
|
|
38
|
+
}
|
|
39
|
+
else if (/^([\d]{1,3}p)([\d]{1,3}p)([\d]{1,3}p)/.test(color)) {
|
|
40
|
+
if (/^([\d]{1,3}p)([\d]{1,3}p)([\d]{1,3}p$)/.test(color))
|
|
41
|
+
return 'rgb(' + color.replace(/^([\d]{1,3}p)([\d]{1,3}p)([\d]{1,3}p)/, '$1,$2,$3').replace(/p/g, '%') + ')';
|
|
42
|
+
else
|
|
43
|
+
return ('rgba(' +
|
|
44
|
+
color
|
|
45
|
+
.replace(/^([\d]{1,3}p)([\d]{1,3}p)([\d]{1,3}p)([\d]+)/, '$1,$2,$3,$4')
|
|
46
|
+
.replace('d', '.')
|
|
47
|
+
.replace(/p/g, '%') +
|
|
48
|
+
')');
|
|
49
|
+
}
|
|
50
|
+
else if (/^(rgb|hsl|hsla|rgba)-/.test(color)) {
|
|
51
|
+
const match = color.match(/^(rgb|hsl|hsla|rgba)-/);
|
|
52
|
+
const colorFunc = match ? match[1] : '';
|
|
53
|
+
if (color.replace(colorFunc, '').match(/^--/))
|
|
54
|
+
return `${colorFunc}(var(${color.replace(colorFunc, '')}))`;
|
|
55
|
+
return `${colorFunc}(${color.replace(colorFunc, '').replace(/^-/, '').replace(/-/g, ',').replace('d', '.')
|
|
56
|
+
.replace(/p/g, '%')})`;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import shadow from './shadow.js';
|
|
2
|
+
export default function filter(valuePortion, custom) {
|
|
3
|
+
let compileValue = '';
|
|
4
|
+
const matchRegEx = /^[-]?([a-zA-Z]+([-][\w]+)?)(?=[-])/;
|
|
5
|
+
valuePortion.split(/__/).forEach((each) => {
|
|
6
|
+
var _a;
|
|
7
|
+
let [fn, value] = ['', ''];
|
|
8
|
+
// css-var
|
|
9
|
+
if (each.match(/--[a-zA-Z]/)) {
|
|
10
|
+
const [functionPortion, functionValuePortion] = [(_a = each.split(/--/)[0]) === null || _a === void 0 ? void 0 : _a.replace(/^-/, ''), each.split(/--/)[1]];
|
|
11
|
+
if (funcAlias.hasOwnProperty(functionPortion)) {
|
|
12
|
+
compileValue += `${functionPortion}(var(--${functionValuePortion})) `;
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const extractFnV = each.match(matchRegEx);
|
|
17
|
+
if (extractFnV) {
|
|
18
|
+
if (funcAlias.hasOwnProperty(extractFnV[1])) {
|
|
19
|
+
fn = funcAlias[extractFnV[1]];
|
|
20
|
+
}
|
|
21
|
+
if (fn === 'drop-shadow') {
|
|
22
|
+
value = shadow(each.replace(matchRegEx, ''), custom);
|
|
23
|
+
value = value ? value : '';
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
value = each.replace(matchRegEx, '').replace(/-(-)?/g, '$1').replace(/p$/, '%').replace(/(?<=[0-9])[d](?=[0-9])/, '.');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
compileValue += `${fn}(${value}) `;
|
|
30
|
+
});
|
|
31
|
+
return compileValue.replace(/[\s]$/, '');
|
|
32
|
+
}
|
|
33
|
+
const funcAlias = {
|
|
34
|
+
b: 'blur',
|
|
35
|
+
blur: 'blur',
|
|
36
|
+
br: 'brightness',
|
|
37
|
+
brightness: 'brightness',
|
|
38
|
+
'drop-shadow': 'drop-shadow',
|
|
39
|
+
ds: 'drop-shadow',
|
|
40
|
+
c: 'contrast',
|
|
41
|
+
contrast: 'contrast',
|
|
42
|
+
g: 'grayscale',
|
|
43
|
+
grayscale: 'grayscale',
|
|
44
|
+
hr: 'hue-rotate',
|
|
45
|
+
'hue-rotate': 'hue-rotate',
|
|
46
|
+
i: 'invert',
|
|
47
|
+
invert: 'invert',
|
|
48
|
+
o: 'opacity',
|
|
49
|
+
opacity: 'opacity',
|
|
50
|
+
saturate: 'saturate',
|
|
51
|
+
s: 'saturate',
|
|
52
|
+
se: 'sepia',
|
|
53
|
+
sepia: 'sepia',
|
|
54
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export default function font(font, custom) {
|
|
2
|
+
font = font.replace(/^[-_]/, '');
|
|
3
|
+
let holder = '';
|
|
4
|
+
font.split(/__/).forEach((e) => {
|
|
5
|
+
if (custom.hasOwnProperty('font') && typeof custom.font === 'object') {
|
|
6
|
+
if (custom.font.hasOwnProperty(e)) {
|
|
7
|
+
holder += custom.font[e] + ', ';
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
if (e.search(/_/) !== -1) {
|
|
12
|
+
holder += '"' + e.replace(/_/g, ' ') + '", ';
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
holder += e + ', ';
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return holder.replace(/,[\s]$/, '');
|
|
19
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import color from './color.js';
|
|
2
|
+
export default function gradient(datas, custom) {
|
|
3
|
+
datas = datas.replace(/^[-]/, '');
|
|
4
|
+
let masterHolder = '';
|
|
5
|
+
datas.split('__').forEach((data) => {
|
|
6
|
+
const matched = data.match(/[-]?(((repeating-)?(conic|linear|radial)-gradient)|(rrg|rg|lg|rcg|cg|rcg|rlg))([\w_-]+)/);
|
|
7
|
+
// console.warn(matched, data);
|
|
8
|
+
if (matched) {
|
|
9
|
+
const grad = matched[1];
|
|
10
|
+
let gradientFunc = '';
|
|
11
|
+
let holder = '';
|
|
12
|
+
data = matched[6].replace(/^[-]([a-z])/, '$1');
|
|
13
|
+
if (alias.hasOwnProperty(grad)) {
|
|
14
|
+
// set gradient to gradient func e.g lineargradient()
|
|
15
|
+
gradientFunc = alias[grad];
|
|
16
|
+
// For Css-Var
|
|
17
|
+
if (data.match(/^--[a-zA-Z]/)) {
|
|
18
|
+
masterHolder += `${gradientFunc}(var(${data})), `;
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
// setting direction/angle/position/shape e.g right/45deg/center/circle
|
|
22
|
+
const m1 = /^[-]?-[0-9]+[d]?[0-9]*(deg|grad|rad|turn)/;
|
|
23
|
+
const m2 = /^((to-)?(right|left|top|bottom)?[-]?(right|left|top|bottom))|^([t]?[rltb]?[rltb])(?=[0-9-])/;
|
|
24
|
+
if (m1.test(data)) {
|
|
25
|
+
const m = m1.exec(data);
|
|
26
|
+
if (m) {
|
|
27
|
+
holder += m[0].replace(/[-]([-])?/, ' $1').replace(/[d](?=[0-9])/, '.') + ', ';
|
|
28
|
+
data = data.replace(m[0], '');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else if (m2.test(data)) {
|
|
32
|
+
const m = m2.exec(data);
|
|
33
|
+
if (m) {
|
|
34
|
+
// console.log(m2.match()[1]);
|
|
35
|
+
if (alias.hasOwnProperty(m[0])) {
|
|
36
|
+
holder += alias[m[0]] + ', ';
|
|
37
|
+
}
|
|
38
|
+
data = data.replace(m[0], '');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
data = data
|
|
42
|
+
.replace(/_([0-9]+)[d]([0-9])/g, ' _$1.$2')
|
|
43
|
+
.replace(/_/g, ' ')
|
|
44
|
+
.replace(/-/g, ',');
|
|
45
|
+
// console.log(data);
|
|
46
|
+
data = data
|
|
47
|
+
.replace(/^[A-Za-z0-9]+/g, (mch) => {
|
|
48
|
+
// console.log(mch);
|
|
49
|
+
const proccessedColor = color(mch.replace(/[,]/, ''), custom);
|
|
50
|
+
return proccessedColor ? ', ' + proccessedColor : mch;
|
|
51
|
+
})
|
|
52
|
+
.replace(/[,][A-Za-z0-9]+/g, (mch) => {
|
|
53
|
+
// console.log(mch);
|
|
54
|
+
const proccessedColor = color(mch.replace(/[,]/, ''), custom);
|
|
55
|
+
return proccessedColor ? ', ' + proccessedColor : mch;
|
|
56
|
+
});
|
|
57
|
+
data = data.replace(/(?<=[0-9])[p](?=[\W]|$)/g, '%').replace(/([0-9])[d]([0-9])/g, '$1.$2');
|
|
58
|
+
// .replace(/(?<=[\W]([0-9])+)[d](?=[0-9])/g, ".");
|
|
59
|
+
holder += data.replace(/^[,]/, '').replace(/[_]/g, '');
|
|
60
|
+
// return gradientFunc + "( " + holder.replace(/,$/, "") + " )";
|
|
61
|
+
masterHolder += gradientFunc + '(' + holder.replace(/,$/, '') + ' ),';
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
} // EOF IF MATACHED
|
|
67
|
+
});
|
|
68
|
+
return masterHolder.replace(/,[\s]?$/, '').replace(/[,]([0-9]+[\.]?[0-9]*(%|px|em|rem|in|mm|cm|in|vw|vh)(?!\)))/g, ' $1');
|
|
69
|
+
}
|
|
70
|
+
const alias = {
|
|
71
|
+
// gradient
|
|
72
|
+
cg: 'conic-gradient',
|
|
73
|
+
rcg: 'repeating-conic-gradient',
|
|
74
|
+
'repeating-conic-gradient': 'repeating-conic-gradient',
|
|
75
|
+
'conic-gradient': 'conic-gradient',
|
|
76
|
+
lg: 'linear-gradient',
|
|
77
|
+
'linear-gradient': 'linear-gradient',
|
|
78
|
+
rg: 'radial-gradient',
|
|
79
|
+
'radial-gradient': 'radial-gradient',
|
|
80
|
+
rlg: 'repeating-linear-gradient',
|
|
81
|
+
'repeating-linear-gradient': 'repeating-linear-gradient',
|
|
82
|
+
rrg: 'repeating-radial-gradient',
|
|
83
|
+
'repeating-radial-gradient': 'repeating-radial-gradient',
|
|
84
|
+
// direction ((to-)?(right|left|top|bottom)?(right|left|top|bottom))|([t]?[rltb]?[rltb])(?=[0-9-])
|
|
85
|
+
r: 'right',
|
|
86
|
+
right: 'right',
|
|
87
|
+
bottom: 'bottom',
|
|
88
|
+
b: 'bottom',
|
|
89
|
+
t: 'top',
|
|
90
|
+
top: 'top',
|
|
91
|
+
l: 'left',
|
|
92
|
+
left: 'left',
|
|
93
|
+
'top-left': 'top left',
|
|
94
|
+
'top-right': 'top rigth',
|
|
95
|
+
'bottom-right': 'bottom right',
|
|
96
|
+
'bottom-left': 'bottom left',
|
|
97
|
+
'left-top': 'left top',
|
|
98
|
+
'right-top': 'rigth top',
|
|
99
|
+
'right-bottom': 'right bottom',
|
|
100
|
+
'left-bottom': 'left bottom',
|
|
101
|
+
tl: 'top left',
|
|
102
|
+
tr: 'top right',
|
|
103
|
+
br: 'bottom right',
|
|
104
|
+
bl: 'bottom left',
|
|
105
|
+
lt: 'left top',
|
|
106
|
+
rt: 'rigth top',
|
|
107
|
+
rb: 'right bottom',
|
|
108
|
+
lb: 'left bottom',
|
|
109
|
+
tor: 'to right',
|
|
110
|
+
'to-right': 'to right',
|
|
111
|
+
'to-bottom': 'to bottom',
|
|
112
|
+
tb: 'to bottom',
|
|
113
|
+
tt: 'to top',
|
|
114
|
+
'to-top': 'to top',
|
|
115
|
+
tol: 'to left',
|
|
116
|
+
'to-left': 'to left',
|
|
117
|
+
'to-top-left': 'to top left',
|
|
118
|
+
'to-top-right': 'to top right',
|
|
119
|
+
'to-bottom-right': 'to bottom right',
|
|
120
|
+
'to-bottom-left': 'to bottom left',
|
|
121
|
+
'to-left-top': 'to left top',
|
|
122
|
+
'to-right-top': 'to right top',
|
|
123
|
+
'to-right-bottom': 'to right bottom',
|
|
124
|
+
'to-left-bottom': 'to left bottom',
|
|
125
|
+
// shr
|
|
126
|
+
ttl: 'to top left',
|
|
127
|
+
ttr: 'to top right',
|
|
128
|
+
tbr: 'to bottom right',
|
|
129
|
+
tbl: 'to bottom left',
|
|
130
|
+
tlt: 'to left top',
|
|
131
|
+
trt: 'to right top',
|
|
132
|
+
trb: 'to right bottom',
|
|
133
|
+
tlb: 'to left bottom',
|
|
134
|
+
'closest-side': 'cs',
|
|
135
|
+
'closest-corner': 'cc',
|
|
136
|
+
'farthest-side': 'fs',
|
|
137
|
+
'farthest-corner': 'fc',
|
|
138
|
+
};
|