aliascss 1.3.0 → 1.3.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/dist/aliascss.js +1 -1
- package/lib/compilers/color.js +22 -4
- package/lib/css-properties-all.js +7 -1
- package/lib/returnPropertyAndValue.js +1 -1
- package/lib/utils/helper.d.ts +7 -0
- package/lib/utils/helper.js +35 -0
- package/package.json +1 -1
package/lib/compilers/color.js
CHANGED
|
@@ -47,15 +47,33 @@ export default function color(color, custom) {
|
|
|
47
47
|
.replace(/p/g, '%') +
|
|
48
48
|
')');
|
|
49
49
|
}
|
|
50
|
-
else if (/^(rgb|hsl|hsla|rgba)-/.test(color)) {
|
|
51
|
-
const match = color.match(/^(rgb|hsl|hsla|rgba)-/);
|
|
50
|
+
else if (/^(rgb|hsl|hsla|rgba|hwb|hwba|lab|oklab|lch|oklch)-/.test(color)) {
|
|
51
|
+
const match = color.match(/^(rgb|hsl|hsla|rgba|hwb|hwba|lab|oklab|lch|oklch)-/);
|
|
52
52
|
const colorFunc = match ? match[1] : '';
|
|
53
53
|
if (color.replace(colorFunc, '').match(/^--/))
|
|
54
54
|
return `${colorFunc}(var(${color.replace(colorFunc, '')}))`;
|
|
55
|
-
return `${colorFunc}(${color.replace(colorFunc, '').replace(/^-/, '').replace(/-/g, '
|
|
56
|
-
.replace(/p/g, '%')})
|
|
55
|
+
return replaceLast(`${colorFunc}(${color.replace(colorFunc, '').replace(/^-/, '').replace(/-/g, ' ').replace(/([0-9])d([0-9])/g, '$1.$2')
|
|
56
|
+
.replace(/p/g, '%')})`, 3, " ", " / ");
|
|
57
|
+
}
|
|
58
|
+
else if (/^p3-/.test(color)) {
|
|
59
|
+
if (color.replace(/p3/, '').match(/^--/))
|
|
60
|
+
return `color(display-p3 (var(${color.replace(/p3/, '')}))`;
|
|
61
|
+
return replaceLast(`color(display-p3 ${color.replace(/p3/, '').replace(/^-/, '').replace(/-/g, ' ').replace('d', '.')
|
|
62
|
+
.replace(/([0-9])p/g, '$1%')})`, 4, " ", " / ");
|
|
57
63
|
}
|
|
58
64
|
else {
|
|
59
65
|
return;
|
|
60
66
|
}
|
|
61
67
|
}
|
|
68
|
+
function replaceLast(str, occurs, target, replacement) {
|
|
69
|
+
var _a;
|
|
70
|
+
if (((_a = str.match(new RegExp(target, 'g'))) === null || _a === void 0 ? void 0 : _a.length) === occurs) {
|
|
71
|
+
const lastIndex = str.lastIndexOf(target);
|
|
72
|
+
if (lastIndex === -1)
|
|
73
|
+
return str;
|
|
74
|
+
return str.slice(0, lastIndex) + replacement + str.slice(lastIndex + target.length);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
return str;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -786,7 +786,13 @@ const cssProps = {
|
|
|
786
786
|
alias: '',
|
|
787
787
|
type: 's',
|
|
788
788
|
// compiler:'',
|
|
789
|
-
values: ['auto:a', 'sRGB', '
|
|
789
|
+
values: ['auto:a', 'sRGB', 'linearRGB']
|
|
790
|
+
},
|
|
791
|
+
'color-interpolation-filters': {
|
|
792
|
+
alias: '',
|
|
793
|
+
type: 's',
|
|
794
|
+
// compiler:'',
|
|
795
|
+
values: ['auto:a', 'sRGB', 'linearRGB']
|
|
790
796
|
},
|
|
791
797
|
'color-scheme': {
|
|
792
798
|
alias: '',
|
|
@@ -148,7 +148,7 @@ bool = false) {
|
|
|
148
148
|
}
|
|
149
149
|
else {
|
|
150
150
|
console.log(`${className}: '${propertyKey}' unable to compile value:${className.replace(propertyKey, '')} returning value as it is`);
|
|
151
|
-
return bool ? [prop, valuePortion.replace(/^-/, '') + ` /* ***Warning:Might not be Valid value *** */`] : prop + ":" + valuePortion.replace(/^-/, '') + ` /* ***Warning:Might not be Valid value *** */`;
|
|
151
|
+
return bool ? [prop, (valuePortion.replace(/^-/, '')) ? valuePortion.replace(/^-/, '') : 'initial' + ` /* ***Warning:Might not be Valid value *** */`] : prop + ":" + (valuePortion.replace(/^-/, '')) ? valuePortion.replace(/^-/, '') : 'initial' + ` /* ***Warning:Might not be Valid value *** */`;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
else {
|
package/lib/utils/helper.d.ts
CHANGED
|
@@ -4,3 +4,10 @@ export declare function cssVarWithDefault(valuePortion: string, compiler?: (a: s
|
|
|
4
4
|
[key: string]: string;
|
|
5
5
|
};
|
|
6
6
|
}) => any, custom?: {}): string | undefined;
|
|
7
|
+
export declare function stringToArray(str: string): string[];
|
|
8
|
+
export declare function objectToCSS(obj: {
|
|
9
|
+
[key: string]: string;
|
|
10
|
+
}, prefix?: string): string;
|
|
11
|
+
export declare function stylesToCSS(stylesObj: {
|
|
12
|
+
[key: string]: string;
|
|
13
|
+
}, selector: string): string;
|
package/lib/utils/helper.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// splitByCommaOutsideParens("(someValue,(nested,value),someValue)");
|
|
2
|
+
// Output: ["someValue", "(nested,value)", "someValue"]
|
|
1
3
|
export function splitByCommaOutsideParens(str) {
|
|
2
4
|
const result = [];
|
|
3
5
|
let current = '';
|
|
@@ -25,6 +27,10 @@ export function splitByCommaOutsideParens(str) {
|
|
|
25
27
|
}
|
|
26
28
|
return result;
|
|
27
29
|
}
|
|
30
|
+
// -----------------------------
|
|
31
|
+
// "--primary-color"=> "var(--primary-color)"
|
|
32
|
+
// "--primary-color:ff0000"=>"var(--primary-color, #ff0000)"
|
|
33
|
+
// "--gap:calc(1rem+var(--spacing))"=>"var(--gap, calc(1rem + var(--spacing)))"
|
|
28
34
|
export function cssVarWithDefault(valuePortion, compiler, custom = {}) {
|
|
29
35
|
if (/^--[a-zA-Z]/.test(valuePortion)) {
|
|
30
36
|
if (valuePortion.includes(':')) {
|
|
@@ -44,3 +50,32 @@ export function cssVarWithDefault(valuePortion, compiler, custom = {}) {
|
|
|
44
50
|
return `var(${valuePortion})`;
|
|
45
51
|
}
|
|
46
52
|
}
|
|
53
|
+
// ----------------------
|
|
54
|
+
// console.log(stringToArray("(apple, banana , cherry)"));
|
|
55
|
+
// Output: ["apple", "banana", "cherry"]
|
|
56
|
+
export function stringToArray(str) {
|
|
57
|
+
return str
|
|
58
|
+
.trim()
|
|
59
|
+
.slice(1, -1) // Remove outer parentheses
|
|
60
|
+
.split(',')
|
|
61
|
+
.map(item => item.trim()); // Split by comma and trim whitespace
|
|
62
|
+
}
|
|
63
|
+
// ---------------------------
|
|
64
|
+
// console.log(objectToCSS({'margin': '10px', 'padding': '5px'}));
|
|
65
|
+
// Output: "{margin:10px; padding:5px}"
|
|
66
|
+
export function objectToCSS(obj, prefix = '') {
|
|
67
|
+
return prefix + '{' +
|
|
68
|
+
Object.entries(obj)
|
|
69
|
+
.map(([key, value]) => `${key}:${value}`)
|
|
70
|
+
.join('; ') +
|
|
71
|
+
'}';
|
|
72
|
+
}
|
|
73
|
+
// ----------------------------
|
|
74
|
+
// console.log(stylesToCSS({'padding': '20px', 'background': 'blue'}, 'body'));
|
|
75
|
+
// Output: "body{padding:20px} body{background:blue}"
|
|
76
|
+
export function stylesToCSS(stylesObj, selector) {
|
|
77
|
+
const cssRules = Object.entries(stylesObj)
|
|
78
|
+
.map(([property, value]) => `${selector}{${property}:${value}}`)
|
|
79
|
+
.join(' ');
|
|
80
|
+
return cssRules;
|
|
81
|
+
}
|