aliascss 1.2.5 → 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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export default function (): string;
@@ -0,0 +1,3 @@
1
+ export default function () {
2
+ return "hello";
3
+ }
@@ -0,0 +1,3 @@
1
+ import statementMaker from'../classPrinter.js';
2
+ XCompiler=statementMaker.make;
3
+
@@ -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, ',').replace('d', '.')
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', 'linerRGB']
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: '',
@@ -0,0 +1,20 @@
1
+ type Property = {
2
+ alias?: string;
3
+ property?: string;
4
+ test?: RegExp;
5
+ type?: string;
6
+ values?: string[];
7
+ groups?: {
8
+ [key: string]: string;
9
+ };
10
+ statement?: string;
11
+ compiler?: (a: string, b: {
12
+ [key: string]: {
13
+ [key: string]: string;
14
+ };
15
+ }) => any;
16
+ };
17
+ declare const cssCustomCompilers: {
18
+ [key: string]: Property;
19
+ };
20
+ export default cssCustomCompilers;
@@ -0,0 +1,9 @@
1
+ const cssCustomCompilers = {
2
+ abs: {
3
+ type: 'group',
4
+ compiler: () => {
5
+ return '';
6
+ }
7
+ }
8
+ };
9
+ export default cssCustomCompilers;
package/lib/prebuild.js CHANGED
@@ -189,38 +189,6 @@ export default {
189
189
  [transform-tx--100p,l0,t0,zi-1]--as-x-screen-left
190
190
  [transform-tx-100p,r0,t0,zi-1]--as-x-screen-right `
191
191
  },
192
- // Box-and-button
193
- // 'x-section':{
194
- // type:'statement',
195
- // statement:`w--x-section-width:100p p--x-section-padding:20px [class~=x-section-spacious]--x-section-padding:80px height--x-section-height:auto`,
196
- // },
197
- // 'x-container':{
198
- // type:'statement',
199
- // statement:`width-100p mla mra pl--x-container-padding:15px pl--x-container-padding:15px bsbb xw--x-container-width:initial
200
- // [class~=x-container-fluid][--x-container-width:100%,m-0-auto]
201
- // [class~=x-container-narrow][--x-container-width:800px]`,
202
- // },
203
- // 'x-row':{
204
- // type:'statement',
205
- // statement:`df fww g-16px m--8px __all-margin-8px i__all-flex-1 [class~=x-row-no-wrap]-fwn [class~=x-row-center]-jcc`,
206
- // },
207
- // 'x-col':{
208
- // type:'statement',
209
- // statement:`df fww g-16px m--8px __all-margin-8px i__all-flex-1 [class~=x-col-no-wrap]-fwn [class~=x-col-center]-jcc
210
- // [class~=x-col-full][flex-grow:1]`,
211
- // },
212
- // 'x-box':{
213
- // type:'statement',
214
- // statement:`bgc--x-box-bg:ffffff p--x-box-padding:16px br--x-box-border-radius:8px border--x-box-border:1px-solid-e0e0e0
215
- // [class~=x-box-shadow]-bxs-0px-2px-8px-0000000000d1`,
216
- // },
217
- // 'x-card':{
218
- // type:'statement',
219
- // statement:`bgc--x-card-bg:ffffff padding--x-card-padding:24px br--x-card-border-radius:12px bxs--x-card-shadow:0px-4px-12px-0000000000d1
220
- // [class~=x-card-interactive][--hover-transform-translateY--4px,--hover-bxs-0-8px-24px-0000000000d15]
221
- // transition-transform-0.3s-ease__box-shadow-0.3s-ease
222
- // [class~=x-card-dark][--x-card-bg:1a1a1a,--x-card-shadow:0px-4px-12px-0000000000d3,color--x-card-color:ffffff]`,
223
- // },
224
192
  'x-divider-text': {
225
193
  type: 'statement',
226
194
  statement: `[df,aic,g12px]
@@ -1,3 +1,3 @@
1
1
  export default function extractMediaPrefix(className: string, prefix: {
2
2
  [key: string]: string;
3
- }, match: RegExp, bool?: boolean): [string, string];
3
+ }, match: RegExp, bool?: boolean): [string[], string];
@@ -1,12 +1,36 @@
1
1
  export default function extractMediaPrefix(className, prefix, match, bool = false) {
2
- var _a;
2
+ var _a, _b, _c;
3
+ const medias = [];
4
+ let cls = className;
5
+ const matchNestedMedia = /@\[(.*?)]/;
6
+ // case 1. single media
3
7
  if (className.match(match)) {
4
8
  const prefixMedia = (_a = className.match(match)) === null || _a === void 0 ? void 0 : _a[0];
5
9
  if (prefixMedia) {
6
10
  if (prefix.hasOwnProperty(prefixMedia)) {
7
- return [prefix[prefixMedia], className.replace(prefixMedia, '')];
11
+ medias.push(prefix[prefixMedia]);
12
+ cls = className.replace(prefixMedia, '');
13
+ // return [[], ]
8
14
  }
9
15
  }
10
16
  }
11
- return ['', className];
17
+ else if (className.match(matchNestedMedia)) { // Nested Media Selector
18
+ (_c = (_b = className.match(matchNestedMedia)) === null || _b === void 0 ? void 0 : _b[1]) === null || _c === void 0 ? void 0 : _c.split(',').map((e) => {
19
+ var _a, _b;
20
+ const suffixedMatch = e + "-";
21
+ if (suffixedMatch.match(match) || ("@" + suffixedMatch).match(match)) {
22
+ const prefixMedia = ((_a = suffixedMatch.match(match)) === null || _a === void 0 ? void 0 : _a[0]) || ((_b = ('@' + suffixedMatch).match(match)) === null || _b === void 0 ? void 0 : _b[0]);
23
+ if (prefixMedia) {
24
+ if (prefix.hasOwnProperty(prefixMedia)) {
25
+ medias.push(prefix[prefixMedia]);
26
+ // return [[], ]
27
+ }
28
+ }
29
+ }
30
+ });
31
+ if (medias.length) {
32
+ cls = className.replace(matchNestedMedia, '');
33
+ }
34
+ }
35
+ return [medias, cls];
12
36
  }
@@ -50,6 +50,8 @@ const media = {
50
50
  '@comps': '@layer components',
51
51
  '@utils': '@layer utilities',
52
52
  '@utilities': '@layer utilities',
53
+ '@starting-style': '@starting-style',
54
+ '@ss': '@starting-style',
53
55
  },
54
56
  };
55
57
  export function createRegexForMedia(prefix) {
@@ -107,6 +107,17 @@ bool = false) {
107
107
  }
108
108
  }
109
109
  const valuePortion = className.replace(propertyKey, '');
110
+ // New Update function value
111
+ if (/^\(.*\)[_]?$/.test(valuePortion)) {
112
+ if (valuePortion.match(/_$/)) {
113
+ const val = valuePortion.replace(/[(_)]/g, '').replace(/,/g, ' ');
114
+ return bool ? [prop, val] : prop + ":" + val;
115
+ }
116
+ else {
117
+ const val = valuePortion.replace(/[(_)]/g, '').replace(/,/g, ', ');
118
+ return bool ? [prop, val] : prop + ":" + val;
119
+ }
120
+ }
110
121
  // case 3: calc function
111
122
  if (/^-calc\(/.test(valuePortion)) {
112
123
  return bool ? [prop, valuePortion.replace(/^-/, '').replace(/([-+/*])([\d]|var\(|calc\()/g, ' $1 $2')] : prop + ":" + valuePortion.replace(/^-/, '').replace(/([-+/*])([\d]|var\(|calc\()/g, ' $1 $2');
@@ -137,7 +148,7 @@ bool = false) {
137
148
  }
138
149
  else {
139
150
  console.log(`${className}: '${propertyKey}' unable to compile value:${className.replace(propertyKey, '')} returning value as it is`);
140
- 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 *** */`;
141
152
  }
142
153
  }
143
154
  else {
@@ -84,8 +84,10 @@ export const compiler = {
84
84
  if (!this.mediaTest)
85
85
  this.mediaTest = createRegexForMedia(this.mediaSelector);
86
86
  // 1. check and extract Media prefix and return className with prefix treatment,
87
- let [media, workingClassName] = extractMediaPrefix(unPrefixedClassName, this.mediaSelector, this.mediaTest);
88
- media = media;
87
+ let [extractedMedia, workingClassName] = extractMediaPrefix(unPrefixedClassName, this.mediaSelector, this.mediaTest);
88
+ const mediaEX = extractedMedia;
89
+ // lint escape for const
90
+ extractedMedia = extractedMedia;
89
91
  // 2. search for '&' which tells us to use selector before or after className
90
92
  if (workingClassName.match(/[&]/)) {
91
93
  const [before, after] = workingClassName.split('&');
@@ -155,8 +157,13 @@ export const compiler = {
155
157
  if (bool === true)
156
158
  return result;
157
159
  this.cache.propertyAndValue[pnv] = result;
158
- if (media) {
159
- stm = `${media}{${beforeClassNameSelector + '.' + className + elementAndPseudo}{${result}${important}}}`;
160
+ if (mediaEX.length) {
161
+ let [bf, af] = ['', ''];
162
+ mediaEX.map((e) => {
163
+ bf = bf + e + "{ ";
164
+ af = af + "}";
165
+ });
166
+ stm = `${bf}${beforeClassNameSelector + '.' + className + elementAndPseudo}{${result}${important}}${af}`;
160
167
  }
161
168
  else {
162
169
  stm = `${beforeClassNameSelector}.${className}${elementAndPseudo}{${result}${important}}`;
@@ -170,7 +177,7 @@ export const compiler = {
170
177
  }
171
178
  }
172
179
  else {
173
- console.log(`Unable to process ${className} [media:${media},pseudoSelector:${elementAndPseudo},imp:${important}]`);
180
+ console.log(`Unable to process ${className} [media:${mediaEX},pseudoSelector:${elementAndPseudo},imp:${important}]`);
174
181
  }
175
182
  },
176
183
  group(str, as) {
@@ -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;
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aliascss",
3
- "version": "1.2.5",
3
+ "version": "1.3.1",
4
4
  "description": "AliasCSS is a CSS post processor.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",