aliascss 1.1.0 → 1.1.2

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.
@@ -53,6 +53,7 @@ export let classPrinter = {
53
53
  // new Update
54
54
  [...el.attributes].map((each) => {
55
55
  // ------------
56
+ // class-group
56
57
  if (testRegExp.test(each.name)) {
57
58
  let value = each.value;
58
59
  let group = each.name.replace(testRegExp, '');
@@ -1872,13 +1872,13 @@ const cssProps = {
1872
1872
  alias: 'p',
1873
1873
  type: 'd',
1874
1874
  compiler: length,
1875
- values: [''],
1875
+ values: ['none:n'],
1876
1876
  },
1877
1877
  'padding-block': {
1878
1878
  alias: '',
1879
1879
  type: 's',
1880
1880
  compiler: length,
1881
- values: [''],
1881
+ values: ['none:n'],
1882
1882
  },
1883
1883
  'padding-block-end': {
1884
1884
  alias: 'pbe',
package/lib/index.d.ts CHANGED
@@ -1,3 +1,16 @@
1
+ import styleToAliascss from "./utils/stylesToAliascss.js";
2
+ export declare const getCompiler: (property: string) => {
3
+ alias?: string | undefined;
4
+ property?: string | undefined;
5
+ test?: RegExp | undefined;
6
+ type?: string | undefined;
7
+ values?: string[] | undefined;
8
+ compiler?: ((a: string, b: {
9
+ [key: string]: {
10
+ [key: string]: string;
11
+ };
12
+ }) => any) | undefined;
13
+ } | null;
1
14
  export declare const main: {
2
15
  [key: string]: any;
3
16
  make: (a: string, b?: string | undefined, c?: boolean | undefined) => string;
@@ -6,3 +19,4 @@ export declare const main: {
6
19
  export declare const styleJSX: (str: string, bool?: boolean) => any;
7
20
  export declare const staticClassNames: any;
8
21
  export declare const extend: (object: {}) => any;
22
+ export declare const convert: typeof styleToAliascss;
package/lib/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  import { compiler } from "./returnStatement.js";
2
+ import cssProps from "./css-properties-all.js";
3
+ import styleToAliascss from "./utils/stylesToAliascss.js";
2
4
  // import { customStaticClassNames } from "./static/customStaticClassNames.js";
5
+ export const getCompiler = (property) => cssProps.hasOwnProperty(property) ? cssProps[property] : null;
3
6
  export const main = compiler;
4
7
  export const styleJSX = (str, bool) => compiler.groupForJs(str, bool);
5
8
  // export const style=()=>{};
6
9
  export const staticClassNames = compiler.staticClassNames;
7
10
  export const extend = (object) => compiler.extend(object);
11
+ export const convert = styleToAliascss;
@@ -1,11 +1,14 @@
1
1
  const attribute = {
2
- test: /^[-]?[\[][a-z0-9-_]+([~*$^]?[=][a-z0-9-_:/.]+)?[\]]/,
2
+ test: /^[-]?[\[][a-z0-9-_:]+([~*$^]?[=][a-z0-9-_:/.]+)?[\]]/,
3
3
  process(className) {
4
4
  const match = className.match(this.test);
5
5
  if (match) {
6
6
  const attr = match[0];
7
7
  if (attr) {
8
- const result = attr.replace(/[=]([a-z0-9-_:/.]+)[\]]/, '="$1"]').replace(/^[-_]/, ""); // replace(/([\[|\]])/g,'\\$1').replace(/([=])/g,'\\$1');
8
+ const attrSplit = attr.split("=")[0];
9
+ const result = attr.replace(attrSplit, attrSplit.replace(/:/g, '\\:'))
10
+ // .replace(/^([-]?[\[][a-z0-9-_:]+)([~*$^]?[=][a-z0-9-_:/.]+)?[\]]/,(m,s,b)=>s.replace(/\:/g,'\:')+b+']')
11
+ .replace(/-(eql|equal)-/, '=').replace(/[=]([a-z0-9-_:/.]+)[\]]/, '="$1"]').replace(/^[-_]/, ""); // replace(/([\[|\]])/g,'\\$1').replace(/([=])/g,'\\$1');
9
12
  return [className.replace(attr, ''), result];
10
13
  }
11
14
  }
@@ -40,6 +40,7 @@ export const compiler = {
40
40
  // className as another-name, bool->only return property and value
41
41
  make(className, as, bool) {
42
42
  let unPrefixedClassName = className;
43
+ let beforeClassNameSelector = '';
43
44
  if (this.prefix && !className.match(new RegExp('^' + this.prefix + "[-]"))) {
44
45
  return null;
45
46
  }
@@ -51,14 +52,24 @@ export const compiler = {
51
52
  // 1. check and extract Media prefix and return className with prefix treatment,
52
53
  let [media, workingClassName] = extractMediaPrefix(unPrefixedClassName, this.mediaSelector, this.mediaTest);
53
54
  media = media;
55
+ // 2. search for '&' which tells us to use selector before or after className
56
+ if (workingClassName.match(/[&]/)) {
57
+ const [before, after] = workingClassName.split('&');
58
+ beforeClassNameSelector = extractPrefix(before + "-display-none")[0] + " ";
59
+ if (!beforeClassNameSelector.trim()) {
60
+ console.error('Not a valid AliasCSS className:' + className, 'Make sure to provide valid css aliascss selector before "&" identifier');
61
+ return null;
62
+ }
63
+ workingClassName = workingClassName.replace(before, '').replace('&', '');
64
+ }
54
65
  let [elementAndPseudo, important] = ['', ''];
55
66
  // workingClassName=workingClassName.replace(/[_][\.]([a-zA-Z])/g,(s,e)=>"_"+'ACSS').replace(/[.]/g,"d").replace(/[%]/g,'p')
56
- // 2. Process --important flag
67
+ // 3. Process --important flag
57
68
  if (/(-i|--important)$/.test(className)) {
58
69
  important = ' !important';
59
70
  workingClassName = workingClassName.replace(/(-i|--important)$/, '');
60
71
  }
61
- // 3. process Pseudo State
72
+ // 4. process Pseudo State
62
73
  const prefixPseudoElementAttribute = extractPrefix(workingClassName);
63
74
  workingClassName = prefixPseudoElementAttribute[1];
64
75
  elementAndPseudo = prefixPseudoElementAttribute[0];
@@ -87,15 +98,15 @@ export const compiler = {
87
98
  }
88
99
  }
89
100
  if (result) {
90
- className = className.replace(/([$.%=\]\[@~:*#+\(\)\/^])/g, '\\$1');
101
+ className = className.replace(/([$.&%=\]\[@~:*#+\(\)\/^])/g, '\\$1');
91
102
  if (bool === true)
92
103
  return result;
93
104
  this.cache.propertyAndValue[pnv] = result;
94
105
  if (media) {
95
- return `${media}{.${(as ? as : className) + elementAndPseudo}{${result}${important}}}`;
106
+ return `${media}{${beforeClassNameSelector + '.' + (as ? as : className) + elementAndPseudo}{${result}${important}}}`;
96
107
  }
97
108
  else {
98
- return `.${(as ? as : className)}${elementAndPseudo}{${result}${important}}`;
109
+ return `${beforeClassNameSelector}.${(as ? as : className)}${elementAndPseudo}{${result}${important}}`;
99
110
  }
100
111
  }
101
112
  else {
@@ -155,7 +166,7 @@ export const compiler = {
155
166
  });
156
167
  return jsStyle;
157
168
  },
158
- // for config
169
+ // obj:{'container':'p20px m-12pxx, 'section':'mt16px'}
159
170
  groupObj(obj) {
160
171
  if (typeof obj !== 'object')
161
172
  return false;
@@ -183,7 +194,26 @@ export const compiler = {
183
194
  },
184
195
  addMedia(obj) {
185
196
  this.mediaSelector = Object.assign(Object.assign({}, this.mediaSelector), obj);
186
- }
197
+ },
198
+ // styleToAliascss(value:string,bool:boolean){
199
+ // let classValue='';
200
+ // let styleValue='';
201
+ // value.split(/\s*;\s*/).forEach((each)=>{
202
+ // const [property,value]=each.match(/:/)?each.split(':'):['',''];
203
+ // if(property && value){
204
+ // if(cssProps.hasOwnProperty(property.trim())){
205
+ // classValue+=`${(bool===true && cssProps[property.trim()].alias)?cssProps[property.trim()].alias:property}-${
206
+ // value.trim().replace(/['"]/g, '').replace(/#/g, '').replace(/\((^\()\)/g, (m,s)=>'-'+s.replace(/[\s]*,[\s]*/g,'-'))
207
+ // .replace(/\s/g, '-').replace(/^var---/g,'-').replace(/-var-/g,'')
208
+ // }`
209
+ // }else{
210
+ // styleValue+=each+'; ';
211
+ // }
212
+ // }else {
213
+ // styleValue+=each+'; ';
214
+ // }
215
+ // })
216
+ // }
187
217
  };
188
218
  // compiler.staticClassNames={...helper().generateStaticClassNames(compiler.cssProps,config['css-global-values'])};
189
219
  // compiler.addCustom('color',customColors)
@@ -0,0 +1,5 @@
1
+ export default function styleToAliascss(data: string, options?: {
2
+ 'JSX': true;
3
+ }): string;
4
+ export declare function process(match: string, styleValue: string, isSingleQuote: boolean, JSX?: boolean): string;
5
+ export declare function processJSX(match: string, styleValue: string): string;
@@ -0,0 +1,65 @@
1
+ import cssProps from "../css-properties-all.js";
2
+ export default function styleToAliascss(data, options) {
3
+ const JSX = (options === null || options === void 0 ? void 0 : options.JSX) ? true : false;
4
+ const matchJSXStyle = /(?<=[\s])style=[\{][\{]([^}]*)[\}][\}]/;
5
+ const matchSingleQuotes = /(?<=[\s])style=[']([^']*)[']/;
6
+ const matchDoubleQuotes = /(?<=[\s])style=["]([^']*)["]/;
7
+ if (JSX) {
8
+ return data.replace(new RegExp(matchJSXStyle, 'g'), (m, s) => processJSX(m, s));
9
+ }
10
+ return data.replace(new RegExp(matchSingleQuotes, 'g'), (m, s) => process(m, s, true))
11
+ .replace(new RegExp(matchDoubleQuotes, 'g'), (m, s) => process(m, s, false));
12
+ }
13
+ export function process(match, styleValue, isSingleQuote, JSX) {
14
+ let contentForStyle = '';
15
+ let contentForClass = '';
16
+ styleValue.split(';').forEach((each) => {
17
+ const split = each.split(':');
18
+ if (split && split.length === 2) {
19
+ const [property, value] = split;
20
+ if (cssProps.hasOwnProperty(property.trim())) {
21
+ contentForClass += `${property.trim()}-${value.trim().replace(/#/g, '').replace(/\s/g, '-').replace(/,/g, "__")} `;
22
+ return;
23
+ }
24
+ }
25
+ contentForStyle += each + "; ";
26
+ });
27
+ if (isSingleQuote) {
28
+ return `class="${contentForClass}" style='${contentForStyle}'`;
29
+ }
30
+ return `class="${contentForClass}" style="${contentForStyle}"`;
31
+ }
32
+ export function processJSX(match, styleValue) {
33
+ let contentForStyle = '';
34
+ let contentForClass = '';
35
+ styleValue.replace(/[,]([\s]*[a-zA-z]+\:)/g, "###$1").split("###").forEach((each) => {
36
+ const split = each.split(':');
37
+ if (split && split.length === 2) {
38
+ const [property, value] = split;
39
+ const formatProperty = property.replace(/([a-z])([A-Z])/g, (m, a, b) => a + '-' + b.toLowerCase());
40
+ if (cssProps.hasOwnProperty(formatProperty.trim())) {
41
+ contentForClass += `${formatProperty.trim()}-${value.trim().replace(/['"]/g, '').replace(/#/g, '').replace(/\s/g, '-').replace(/,/g, "__")} `;
42
+ return;
43
+ }
44
+ }
45
+ contentForStyle += each + ", ";
46
+ });
47
+ return `className="${contentForClass}" style={{${contentForStyle}}}`;
48
+ }
49
+ // export function processJSXOld(match:string,styleValue:string){
50
+ // const formatStyleValue=styleValue.replace(/[,]([\s]*[a-zA-z]+\:)/g,"###").split("###");
51
+ // let styleOjb:{[key:string]:string}={};
52
+ // eval(`styleOjb=${styleValue}`);
53
+ // console.log(styleOjb);
54
+ // const contentForStyle:{[key:string]:string}={};
55
+ // let contentForClass=''
56
+ // Object.keys(styleOjb).forEach((key:string)=>{
57
+ // const property=key.replace(/([a-z])([A-Z])/g,(m,a,b)=>a+'-'+b.toLowerCase());
58
+ // if(cssProps.hasOwnProperty(property)){
59
+ // contentForClass+=`${property.trim()}-${(styleOjb[key]+" ").trim().replace(/#/g,'').replace(/\s/g,'-').replace(/,/g,"__")} `
60
+ // return
61
+ // }
62
+ // contentForStyle[key]=styleOjb[key];
63
+ // });
64
+ // return `className="${contentForClass}" style={${JSON.stringify(contentForStyle)}}`
65
+ // }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aliascss",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "AliasCSS is a CSS post processor.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -58,7 +58,8 @@
58
58
  "postcss": "^8.4.39",
59
59
  "postcss-discard-duplicates": "^7.0.0",
60
60
  "postcss-sort-media-queries": "^5.2.0",
61
- "postcss-sorting": "^8.0.2"
61
+ "postcss-sorting": "^8.0.2",
62
+ "safe-eval": "^0.4.1"
62
63
  },
63
64
  "homepage": "https://github.com/Rodolopho/acss-lite#readme"
64
65
  }
package/ui/button.html ADDED
@@ -0,0 +1,53 @@
1
+ <div data-size="xxl" data-type="secondary">
2
+ <button
3
+ class="c-fff cp _all-bsbb p8px-12px bg-7F56D9 bxs-0px-1px-2px-0160240400d05 br-8px jcc aic g-4px dif b1px-primary600-solid text-sm fw6 btn-md btn-lg btn-xl btn-2xl btn-xxl btn"
4
+ class-btn='--is-[data-type=secondary]&--hover-bgc-f9fafb --is-[data-type=secondary]&--hover-bc-d0d4dd --is-[data-type=secondary]&bgc-fff --is-[data-type=secondary]&bc-d0d5dd --is-[data-type=secondary]&c-344054 --is-[disabled]&-bgc-F2F4F7 --is-[disabled]&-bc-EAECF0 --is-[disabled]&-c-98A2B3'
5
+ class-btn[--hover]="--is-[disabled]&-bgc-F2F4F7 --is-[disabled]&cna --is-[disabled]&-bc-EAECF0 b-1px-s-6941C6 bgc-6941C6 bxs-0px-1px-2px-0px-0160240400d05"
6
+ class-btn-md="--is-[data-size=md]&-p10px-14px"
7
+ class-btn-lg=" --is-[data-size=lg]&-p10px-16px --is-[data-size=lg]&-text-md"
8
+ class-btn-xl="--is-[data-size=xl]&-p12px-18px --is-[data-size=xl]&-g-6px --is-[data-size=xl]&-text-md"
9
+ class-btn-xxl="--is-[data-size=xxl]&-p16px-22px --is-[data-size=xxl]&-g-10px --is-[data-size=xxl]&-text-lg"
10
+ class-btn-2xl="--is-[data-size=2xl]&-p16px-22px --is-[data-size=2xl]&-g-10px --is-[data-size=2xl]&-text-lg"
11
+ style="">
12
+ <span class="btn-addon"
13
+ class-btn-addon="--is-[data-size=xxl]&-w24px --is-[data-size=xxl]&-h24px --is-[data-size=2xl]&-w24px --is-[data-size=2xl]&-h24px --is-[disabled]&-b-1d67px-solid-98A2B3 --is-[data-type=secondary]&-bc-98A2B3 lt df bsbb w20px h20px br100p b-1d67px-white-solid"
14
+ style=""></span>
15
+ <span class=" ff-Inter ww-break-word ">Button CTA</span>
16
+ <span class="rt btn-addon"></span>
17
+ </button>
18
+ </div>
19
+ <div data-size="xxl" data-type="secondary" [data-type]>
20
+ <div class="
21
+ ac-wrapper
22
+ _button-c-fff _button-cp _all-bsbb _button-p8px-12px _button-bg-7F56D9 _button-bxs-0px-1px-2px-0160240400d05
23
+ _button-br-8px _button-jcc _button-aic _button-g-4px _button-dif _button-b1px-primary600-solid text-sm
24
+ _button-fw6 btn-md btn-lg btn-xl btn-2xl btn-xxl btn
25
+ "
26
+ class-btn="c-fff cp _all-bsbb p8px-12px bg-7F56D9 bxs-0px-1px-2px-0160240400d05 br-8px jcc aic g-4px dif b1px-primary600-solid text-sm fw6"
27
+ class-btn[--hover]="--is-[disabled]&-bgc-F2F4F7 --is-[disabled]&cna --is-[disabled]&-bc-EAECF0 b-1px-s-6941C6 bgc-6941C6 bxs-0px-1px-2px-0px-0160240400d05"
28
+ class-btn-md="--is-[data-size=md]&-p10px-14px"
29
+ class-btn-lg=" --is-[data-size-eql-lg]&-p10px-16px --is-[data-size=lg]&-text-md"
30
+ class-btn-xl="--is-[data-size=xl]&-p12px-18px --is-[data-size=xl]&-g-6px --is-[data-size=xl]&-text-md"
31
+ class-btn-xxl="--is-[data-size=xxl]&-p16px-22px --is-[data-size=xxl]&-g-10px --is-[data-size=xxl]&-text-lg"
32
+ >
33
+
34
+ <!-- Main Content -->
35
+ <button
36
+ class="c-fff cp _all-bsbb p8px-12px bg-7F56D9 bxs-0px-1px-2px-0160240400d05 br-8px jcc aic g-4px dif b1px-primary600-solid text-sm fw6 btn-md btn-lg btn-xl btn-2xl btn-xxl btn"
37
+ class-btn='--is-[data-type=secondary]&--hover-bgc-f9fafb --is-[data-type=secondary]&--hover-bc-d0d4dd --is-[data-type=secondary]&bgc-fff --is-[data-type=secondary]&bc-d0d5dd --is-[data-type=secondary]&c-344054 --is-[disabled]&-bgc-F2F4F7 --is-[disabled]&-bc-EAECF0 --is-[disabled]&-c-98A2B3'
38
+ class-btn[--hover]="--is-[disabled]&-bgc-F2F4F7 --is-[disabled]&cna --is-[disabled]&-bc-EAECF0 b-1px-s-6941C6 bgc-6941C6 bxs-0px-1px-2px-0px-0160240400d05"
39
+ class-btn-md="--is-[data-size=md]&-p10px-14px"
40
+ class-btn-lg=" --is-[data-size=lg]&-p10px-16px --is-[data-size=lg]&-text-md"
41
+ class-btn-xl="--is-[data-size=xl]&-p12px-18px --is-[data-size=xl]&-g-6px --is-[data-size=xl]&-text-md"
42
+ class-btn-xxl="--is-[data-size=xxl]&-p16px-22px --is-[data-size=xxl]&-g-10px --is-[data-size=xxl]&-text-lg"
43
+ class-btn-2xl="--is-[data-size=2xl]&-p16px-22px --is-[data-size=2xl]&-g-10px --is-[data-size=2xl]&-text-lg"
44
+ style="">
45
+ <span class="btn-addon"
46
+ class-btn-addon="--is-[data-size=xxl]&-w24px --is-[data-size=xxl]&-h24px --is-[data-size=2xl]&-w24px --is-[data-size=2xl]&-h24px --is-[disabled]&-b-1d67px-solid-98A2B3 --is-[data-type=secondary]&-bc-98A2B3 lt df bsbb w20px h20px br100p b-1d67px-white-solid"
47
+ style=""></span>
48
+ <span class=" ff-Inter ww-break-word ">Button CTA</span>
49
+ <span class="rt btn-addon"></span>
50
+ </button>
51
+ <!-- End Main Content -->
52
+ </div>
53
+ </div>