aliascss 1.4.7 → 1.5.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/bin/aliascss.js +118 -1
  3. package/dist/aliascss.js +1 -1
  4. package/jestconfig.json +1 -3
  5. package/lib/build/index.js +136 -19
  6. package/lib/classPrinter.d.ts +1 -1
  7. package/lib/classPrinter.js +351 -23
  8. package/lib/compilers/border.js +106 -27
  9. package/lib/compilers/clipPath.js +79 -6
  10. package/lib/compilers/color.js +150 -21
  11. package/lib/compilers/filter.js +90 -3
  12. package/lib/compilers/font.js +39 -11
  13. package/lib/compilers/gradient.js +43 -27
  14. package/lib/compilers/length.js +34 -9
  15. package/lib/compilers/shadow.js +60 -26
  16. package/lib/compilers/stringAndContent.js +39 -2
  17. package/lib/compilers/timingFunction.js +57 -6
  18. package/lib/compilers/transform.js +118 -48
  19. package/lib/compilers/transition.js +79 -11
  20. package/lib/compilers/url.js +53 -3
  21. package/lib/config.d.ts +1 -0
  22. package/lib/config.js +1 -0
  23. package/lib/custom-css-compilers.js +1 -68
  24. package/lib/index.d.ts +9 -9
  25. package/lib/node/compileFile-BK-291026.d.ts +27 -0
  26. package/lib/node/compileFile-BK-291026.js +309 -0
  27. package/lib/node/compileFile-bk.d.ts +14 -12
  28. package/lib/node/compileFile-bk.js +263 -252
  29. package/lib/node/compileFile.js +1 -1
  30. package/lib/node/extractClassNamesFromFile.js +208 -86
  31. package/lib/prebuild.d.ts +26 -0
  32. package/lib/prebuild.js +0 -6
  33. package/lib/prefix/element-selector.js +93 -20
  34. package/lib/prefix/extractPrefix.d.ts +1 -1
  35. package/lib/prefix/extractPrefix.js +113 -70
  36. package/lib/returnPropertyAndValue-bk-301026.d.ts +30 -0
  37. package/lib/returnPropertyAndValue-bk-301026.js +219 -0
  38. package/lib/returnPropertyAndValue.js +26 -25
  39. package/lib/returnStatement-bk-291026.d.ts +5 -0
  40. package/lib/returnStatement-bk-291026.js +470 -0
  41. package/lib/returnStatement.d.ts +1 -0
  42. package/lib/returnStatement.js +120 -29
  43. package/lib/utils/helper.js +16 -2
  44. package/lib/x-classes/x-bundle.d.ts +26 -0
  45. package/lib/x-classes/x-bundle.js +2 -1
  46. package/lib/x-classes/x-extras.js +1 -1
  47. package/lib/x-classes/x-form-components.js +2 -1
  48. package/lib/x-classes/x-row-col.d.ts +29 -0
  49. package/lib/x-classes/x-row-col.js +52 -0
  50. package/llms.txt +326 -0
  51. package/package.json +3 -1
  52. package/tsconfig.json +1 -0
  53. package/tsconfig.test.json +10 -0
@@ -1,4 +1,5 @@
1
1
  import color from './color.js';
2
+ const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
2
3
  export default function gradient(datas, custom) {
3
4
  datas = datas.replace(/^[-]/, '');
4
5
  let masterHolder = '';
@@ -6,61 +7,66 @@ export default function gradient(datas, custom) {
6
7
  if (data.match(/[-]?(((repeating-)?(conic|linear|radial)-gradient)|(rrg|rg|lg|rcg|cg|rcg|rlg))[\(]/)) {
7
8
  masterHolder += data.replace(/[_]/g, ' ') + ', ';
8
9
  }
9
- const matched = data.match(/[-]?(((repeating-)?(conic|linear|radial)-gradient)|(rrg|rg|lg|rcg|cg|rcg|rlg))([-_][\w_-]+)/);
10
- // console.warn(matched, data);
10
+ // ".", "/" and "%" are allowed so stops like red/0.5, 0.5turn and 30% aren't cut off (fix 4)
11
+ const matched = data.match(/[-]?(((repeating-)?(conic|linear|radial)-gradient)|(rrg|rg|lg|rcg|cg|rcg|rlg))([-_][\w_.\/#%-]+)/);
11
12
  if (matched) {
12
13
  const grad = matched[1];
13
14
  let gradientFunc = '';
14
15
  let holder = '';
15
- data = matched[6].replace(/^[-]([a-z])/, '$1');
16
+ // "%" works exactly like "p", and "." between digits exactly like "d" (12.5p = 12d5p)
17
+ data = matched[6].replace(/^[-]([a-z#])/, '$1').replace(/%/g, 'p').replace(/(?<!\/\d*)(\d)\.(\d)/g, '$1d$2'); // not in alpha: red/0.5 stays as is
16
18
  if (alias.hasOwnProperty(grad)) {
17
19
  // set gradient to gradient func e.g lineargradient()
18
20
  gradientFunc = alias[grad];
21
+ const isLinear = /linear/.test(gradientFunc);
22
+ const isConic = /conic/.test(gradientFunc);
19
23
  // For Css-Var
20
24
  if (data.match(/^--[a-zA-Z]/)) {
21
25
  masterHolder += `${gradientFunc}(var(${data})), `;
22
26
  return;
23
27
  }
24
28
  // setting direction/angle/position/shape e.g right/45deg/center/circle
25
- const m1 = /^[-]?-[0-9]+[d]?[0-9]*(deg|grad|rad|turn)/;
26
- const m2 = /^((to-)?(right|left|top|bottom)?[-]?(right|left|top|bottom))|^([t]?[rltb]?[rltb])(?=[0-9-])/;
29
+ const m1 = /^[-]?-?[0-9]+[d]?[0-9]*(deg|grad|rad|turn)/;
27
30
  if (m1.test(data)) {
28
31
  const m = m1.exec(data);
29
32
  if (m) {
30
- holder += m[0].replace(/[-]([-])?/, ' $1').replace(/[d](?=[0-9])/, '.') + ', ';
33
+ const angle = m[0].replace(/[-]([-])?/, ' $1').replace(/[d](?=[0-9])/, '.');
34
+ holder += (isConic ? ' from' : '') + angle + ', '; // conic needs "from 45deg" (fix 5)
31
35
  data = data.replace(m[0], '');
32
36
  }
33
37
  }
34
- else if (m2.test(data)) {
35
- const m = m2.exec(data);
38
+ else {
39
+ const m = DIRECTION.exec(data); // every alias key, longest first (fix 1)
36
40
  if (m) {
37
- // console.log(m2.match()[1]);
38
- if (alias.hasOwnProperty(m[0])) {
39
- holder += alias[m[0]] + ', ';
40
- }
41
- data = data.replace(m[0], '');
41
+ let dir = alias[m[1]];
42
+ // a linear gradient takes "to <side>", radial/conic take "at <position>" (fix 2)
43
+ if (isLinear && !/^to /.test(dir))
44
+ dir = 'to ' + dir;
45
+ else if (!isLinear && !/^to /.test(dir))
46
+ dir = 'at ' + dir;
47
+ holder += dir + ', ';
48
+ data = data.replace(m[1], '');
42
49
  }
43
50
  }
44
51
  data = data
45
52
  .replace(/_([0-9]+)[d]([0-9])/g, ' _$1.$2')
46
53
  .replace(/_/g, ' ')
47
54
  .replace(/-/g, ',');
48
- // console.log(data);
49
- data = data
50
- .replace(/^[A-Za-z0-9]+/g, (mch) => {
51
- // console.log(mch);
52
- const proccessedColor = color(mch.replace(/[,]/, ''), custom);
53
- return proccessedColor ? ', ' + proccessedColor : mch;
54
- })
55
- .replace(/[,][A-Za-z0-9]+/g, (mch) => {
56
- // console.log(mch);
57
- const proccessedColor = color(mch.replace(/[,]/, ''), custom);
58
- return proccessedColor ? ', ' + proccessedColor : mch;
55
+ // Colours first, exactly as before: any token (red, f00, 00f, slateTheme3, 25500000080p…),
56
+ // now also with alpha (red/0.5) (fix 4). Converted colours are parked behind placeholders so
57
+ // the number fixes below can't touch them: #d9d9e0 used to become #d9.9e0 (fix 3).
58
+ const colors = [];
59
+ data = data.replace(/(^|[,])(#?[A-Za-z0-9]+(?:\/[0-9.]+)?)/g, (mch, sep, value) => {
60
+ const processedColor = color(value, custom);
61
+ if (!processedColor)
62
+ return mch;
63
+ colors.push(processedColor);
64
+ return ', \u0000' + (colors.length - 1) + '\u0000';
59
65
  });
60
66
  data = data.replace(/(?<=[0-9])[p](?=[\W]|$)/g, '%').replace(/([0-9])[d]([0-9])/g, '$1.$2');
61
- // .replace(/(?<=[\W]([0-9])+)[d](?=[0-9])/g, ".");
67
+ data = data.replace(/\u0000(\d+)\u0000/g, (_m, i) => colors[Number(i)]);
62
68
  holder += data.replace(/^[,]/, '').replace(/[_]/g, '');
63
- // return gradientFunc + "( " + holder.replace(/,$/, "") + " )";
69
+ // keep the original spacing: the final ",50%" -> " 50%" step below relies on " )"
64
70
  masterHolder += gradientFunc + '(' + holder.replace(/,$/, '') + ' ),';
65
71
  }
66
72
  else {
@@ -131,7 +137,7 @@ const alias = {
131
137
  tbr: 'to bottom right',
132
138
  tbl: 'to bottom left',
133
139
  tlt: 'to left top',
134
- trt: 'to right top',
140
+ trt: 'to right top',
135
141
  trb: 'to right bottom',
136
142
  tlb: 'to left bottom',
137
143
  'closest-side': 'cs',
@@ -139,3 +145,13 @@ const alias = {
139
145
  'farthest-side': 'fs',
140
146
  'farthest-corner': 'fc',
141
147
  };
148
+ // Direction/position keys (not the gradient names or the shape keywords), longest first so
149
+ // "to-top-left" wins over "to-top", and a key must be followed by "-", "_" or the end:
150
+ // "r" doesn't match the start of "red".
151
+ const DIRECTION = new RegExp('^(' +
152
+ Object.keys(alias)
153
+ .filter((k) => !/gradient$|^(cg|rcg|lg|rg|rlg|rrg)$|^(closest|farthest)-/.test(k))
154
+ .sort((a, b) => b.length - a.length)
155
+ .map(escape)
156
+ .join('|') +
157
+ ')(?=[-_]|$)');
@@ -1,17 +1,42 @@
1
1
  export default function length(data) {
2
2
  if (data.match(/^-clamp\(/)) {
3
- return data.replace(/^-/, '')
4
- .replace(/([,+-/*])/g, '$1 ')
5
- .replace(/([+-/*])/g, ' $1');
3
+ // Note: [,+-/*] is a RANGE from "+" to "/" (it includes "," "-" "." "/"), so every
4
+ // decimal became "1 . 5rem" and a negative "-1rem" became " - 1rem".
5
+ const vars = [];
6
+ const v = data.replace(/^-/, '')
7
+ .replace(/var\(--[\w-]+(?:,[^()]*)?\)/g, (m) => { vars.push(m); return '\u0000' + (vars.length - 1) + '\u0000'; }) // keep --var-names intact
8
+ .replace(/(\d)d(\d)/g, '$1.$2') // 1d5rem -> 1.5rem
9
+ .replace(/(\d)p(?=[,)\s+*/-]|$)/g, '$1%') // 50p -> 50%
10
+ .replace(/\s*,\s*/g, ' , ') // "a , b", as before
11
+ .replace(/\s*([+*/])\s*/g, ' $1 ') // operators get spaces
12
+ .replace(/([\w%)\u0000])\s*-\s*(?=[\w.(\u0000])/g, '$1 - '); // "-" is subtraction only after a value
13
+ return v.replace(/\u0000(\d+)\u0000/g, (_m, i) => vars[Number(i)]);
6
14
  }
7
15
  else {
8
- return data.replace(/[-]?fit-content-([-]?\w+)/g, ' fit-content( $1 )')
16
+ // "." between digits works exactly like "d" (12.5rem = 12d5rem)
17
+ return data.replace(/(\d)\.(\d)/g, '$1d$2').replace(/[-]?fit-content-([-]?\w+)/g, ' fit-content( $1 )')
9
18
  .replace(/[-]([-]?[0-9])/g, ' $1').replace(/([\d])d([\d])/g, '$1.$2').replace(/-auto/g, ' auto')
10
- .replace(/([\d])p[\s]/g, "$1% ").replace(/([\d])p$/, "$1%").replace(/-(f|m)/g, '$1');
19
+ .replace(/([\d])p[\s]/g, "$1% ").replace(/([\d])p$/, "$1%").replace(/([\d])p(?=[,)])/g, "$1%").replace(/-(f|m)/g, '$1'); // 100p inside min()/max()
11
20
  }
12
21
  }
13
22
  export const lenByNumPer = (value) => value.replace(/[-]([-]?[\w])/g, ' $1').replace(/([\d])d([\d])/g, '$1.$2').replace(/([\d])p[\s]/g, "$1% ").replace(/([\d])p$/, "$1%").replace(/[\s]by[\s]/g, ' / ').replace(/auto flow/g, 'auto-flow');
14
- // const lenNumPer=(value:string)=>value.replace(/[-]([-]?[\w])/g,' $1').replace(/([\d])d([\d])/g,'$1.$2').replace(/([\d])p[\s]/g,"$1% ").replace(/([\d])p$/,"$1%").replace(/([a-z])([\d-])/g,'$1 $2');
15
- // const signedLenNumPer=(value:string)=>value.replace(/([\d])d([\d])/g,'$1.$2').replace(/([a-z])([\d-])/g,'$1 $2').replace(/([\d])p[\s]/g,"$1% ").replace(/([\d])p$/,"$1%").replace(/[-]([a-z])/g,'$1');
16
- // const lenByNumPer=(value:string)=>value.replace(/[-]([-]?[\w])/g,' $1').replace(/([\d])d([\d])/g,'$1.$2').replace(/([\d])p[\s]/g,"$1% ").replace(/([\d])p$/,"$1%").replace(/[\s]by[\s]/g,' / ');
17
- // const lenFitContent=(value:string)=>value.replace(/fit-content-([-]?\w+)/,'fit-content( $1 )').replace(/[-]([-]?[\w])/g,' $1').replace(/([\d])d([\d])/g,' $1.$2 ').replace(/([\d])p[\s]/g,"$1% ").replace(/([\d])p$/,"$1%");
23
+ /*
24
+ export default function length(data:string){
25
+ if(data.match(/^-clamp\(/)){
26
+ return data.replace(/^-/,'')
27
+ .replace(/([,+-/*])/g,'$1 ')
28
+ .replace(/([+-/*])/g,' $1')
29
+ }else{
30
+ return data.replace(/[-]?fit-content-([-]?\w+)/g,' fit-content( $1 )')
31
+ .replace(/[-]([-]?[0-9])/g,' $1').replace(/([\d])d([\d])/g,'$1.$2').replace(/-auto/g,' auto')
32
+ .replace(/([\d])p[\s]/g,"$1% ").replace(/([\d])p$/,"$1%").replace(/-(f|m)/g,'$1')
33
+ }
34
+ }
35
+ export const lenByNumPer=(value:string)=>value.replace(/[-]([-]?[\w])/g,' $1').replace(/([\d])d([\d])/g,'$1.$2').replace(/([\d])p[\s]/g,"$1% ").replace(/([\d])p$/,"$1%").replace(/[\s]by[\s]/g,' / ').replace(/auto flow/g,'auto-flow');
36
+
37
+
38
+ // const lenNumPer=(value:string)=>value.replace(/[-]([-]?[\w])/g,' $1').replace(/([\d])d([\d])/g,'$1.$2').replace(/([\d])p[\s]/g,"$1% ").replace(/([\d])p$/,"$1%").replace(/([a-z])([\d-])/g,'$1 $2');
39
+ // const signedLenNumPer=(value:string)=>value.replace(/([\d])d([\d])/g,'$1.$2').replace(/([a-z])([\d-])/g,'$1 $2').replace(/([\d])p[\s]/g,"$1% ").replace(/([\d])p$/,"$1%").replace(/[-]([a-z])/g,'$1');
40
+ // const lenByNumPer=(value:string)=>value.replace(/[-]([-]?[\w])/g,' $1').replace(/([\d])d([\d])/g,'$1.$2').replace(/([\d])p[\s]/g,"$1% ").replace(/([\d])p$/,"$1%").replace(/[\s]by[\s]/g,' / ');
41
+ // const lenFitContent=(value:string)=>value.replace(/fit-content-([-]?\w+)/,'fit-content( $1 )').replace(/[-]([-]?[\w])/g,' $1').replace(/([\d])d([\d])/g,' $1.$2 ').replace(/([\d])p[\s]/g,"$1% ").replace(/([\d])p$/,"$1%");
42
+ */
@@ -1,6 +1,8 @@
1
1
  import color from './color.js';
2
2
  export default function shadow(data, custom) {
3
3
  let compileValue = '';
4
+ if (/^-?none$/.test(data))
5
+ return 'none';
4
6
  data.split(/__/).forEach((e) => {
5
7
  let eachValue = ' ';
6
8
  let len = '';
@@ -12,15 +14,16 @@ export default function shadow(data, custom) {
12
14
  if (!e.startsWith('-'))
13
15
  e = "-" + e;
14
16
  // fix Zero
15
- e = e.replace(/(?<=-)0(?=-)/g, '0px').replace(/([-][0-9pd]{6,})/, (a) => a.replace(/p/g, 'xer'));
16
- const match = e.match(/([-]?[-]?[0-9]{1,3}[d/.]?[0-9]*(px|em|p|fr|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))+/);
17
+ // a 0 at the end counts too: shadow-0-0 -> 0px 0px
18
+ e = e.replace(/(?<=-)0(?=-|$)/g, '0px').replace(/([-][0-9pd]{6,})/, (a) => a.replace(/p/g, 'xer'));
19
+ const match = e.match(/([-]?[-]?[0-9]{1,3}[d/.]?[0-9]*(px|pt|pc|em|fr|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|p))+/); // pt/pc before p
17
20
  if (match) {
18
21
  len = match[0];
19
22
  e = e.replace(len, '');
20
23
  }
21
24
  if (len) {
22
25
  // eachValue+=len.replace(/-0px-/g,'-0-').replace(/[-]([-]?[\d])/g,' $1').trim()+" ";
23
- eachValue += len.replace(/[-]([-]?[\d])/g, ' $1').trim() + " ";
26
+ eachValue += len.replace(/[-]([-]?[\d])/g, ' $1').replace(/(\d)d(\d)/g, '$1.$2').trim() + " "; // 1d5px -> 1.5px
24
27
  const col = color(e.replace(/xer/g, 'p'), custom);
25
28
  if (col) {
26
29
  eachValue += col + " ";
@@ -31,27 +34,58 @@ export default function shadow(data, custom) {
31
34
  });
32
35
  return compileValue.replace(/[,]$/, '').replace(/%x/g, '%').trim();
33
36
  }
34
- const ref = `/* Keyword values */
35
- box-shadow: none;
36
-
37
- /* A color and two length values */
38
- /* <color> | <length> | <length> */
39
- box-shadow: red 60px -16px;
40
-
41
- /* Three length values and a color */
42
- /* <length> | <length> | <length> | <color> */
43
- box-shadow: 10px 5px 5px black;
44
-
45
- /* Four length values and a color */
46
- /* <length> | <length> | <length> | <length> | <color> */
47
- box-shadow: 2px 2px 2px 1px rgb(0 0 0 / 20%);
48
-
49
- /* inset, length values, and a color */
50
- /* <inset> | <length> | <length> | <color> */
51
- box-shadow: inset 5em 1em gold;
37
+ /*
38
+ import color from './color.js';
52
39
 
53
- /* Any number of shadows, separated by commas */
54
- box-shadow:
55
- 3px 3px red inset,
56
- -1em 0 0.4em olive;
57
- `;
40
+ export default function shadow(data: string, custom: { [key: string]: { [key: string]: string } }) {
41
+ let compileValue='';
42
+ data.split(/__/).forEach((e)=>{
43
+ let eachValue=' ';
44
+ let len='';
45
+ const col='';
46
+ if (e.match(/^[-]?(i|inset)/)) {
47
+ eachValue += 'inset ';
48
+ e=e.replace(/^[-]?(inset|i)/,'');
49
+ }
50
+ if(!e.startsWith('-')) e="-"+e;
51
+ // fix Zero
52
+ e=e.replace(/(?<=-)0(?=-)/g,'0px').replace(/([-][0-9pd]{6,})/,(a)=>a.replace(/p/g,'xer'));
53
+ const match=e.match(/([-]?[-]?[0-9]{1,3}[d/.]?[0-9]*(px|em|p|fr|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc))+/);
54
+ if(match){
55
+ len=match[0];
56
+ e=e.replace(len,'')
57
+ }
58
+ if(len){
59
+ // eachValue+=len.replace(/-0px-/g,'-0-').replace(/[-]([-]?[\d])/g,' $1').trim()+" ";
60
+ eachValue+=len.replace(/[-]([-]?[\d])/g,' $1').trim()+" ";
61
+ const col=color(e.replace(/xer/g,'p'),custom);
62
+ if(col) {
63
+ eachValue+=col+" ";
64
+ }
65
+ }
66
+ compileValue+=eachValue + ",";
67
+
68
+ // search for length /()/
69
+ })
70
+ return compileValue.replace(/[,]$/,'').replace(/%x/g,'%').trim();
71
+ }
72
+ */
73
+ // const ref =`/* Keyword values */
74
+ // box-shadow: none;
75
+ // /* A color and two length values */
76
+ // /* <color> | <length> | <length> */
77
+ // box-shadow: red 60px -16px;
78
+ // /* Three length values and a color */
79
+ // /* <length> | <length> | <length> | <color> */
80
+ // box-shadow: 10px 5px 5px black;
81
+ // /* Four length values and a color */
82
+ // /* <length> | <length> | <length> | <length> | <color> */
83
+ // box-shadow: 2px 2px 2px 1px rgb(0 0 0 / 20%);
84
+ // /* inset, length values, and a color */
85
+ // /* <inset> | <length> | <length> | <color> */
86
+ // box-shadow: inset 5em 1em gold;
87
+ // /* Any number of shadows, separated by commas */
88
+ // box-shadow:
89
+ // 3px 3px red inset,
90
+ // -1em 0 0.4em olive;
91
+ // `
@@ -3,12 +3,18 @@ export function string(str, custom) {
3
3
  return str.replace(/^[-]/, '').replace(/__/g, ', ');
4
4
  }
5
5
  export default function content(str) {
6
- // for CSS entities
6
+ // the value arrives with its leading "-" (content-_2022 -> "-_2022"): strip it first,
7
+ // otherwise the entity check below never matched and _2022 became the text " 2022"
8
+ str = str.replace(/^[-]/, '');
9
+ // for CSS entities: _2022 -> "\2022", _2014_00a0 -> "\2014\00a0"
7
10
  if (str.match(/^_/)) {
8
11
  // return '"' + str.split("_").join(" \\").trim() + '"';
9
12
  return '"' + str.slice(1).split('_').map(c => '\\' + c).join('') + '"';
10
13
  }
11
- str = str.replace(/^[-]/, '');
14
+ // raw functions pass through: attr(data-label), counter(item), counters(item,_"."), var(--x)
15
+ if (/^[a-z-]+\(.*\)$/.test(str)) {
16
+ return str.replace(/_/g, ' ');
17
+ }
12
18
  // attr() or counter()
13
19
  const data = str.match(/^(attr|counter)?[-_]([\w-]+)/);
14
20
  if (data) {
@@ -22,3 +28,34 @@ export default function content(str) {
22
28
  // return plain string with quotes
23
29
  return '"' + str.replace(/[_]/g, ' ') + '"';
24
30
  }
31
+ /*
32
+ export function string(str: string, custom: { [key: string]: { [key: string]: string } }) {
33
+ // return string as it is only changes __ to ,
34
+ return str.replace(/^[-]/, '').replace(/__/g,', ');
35
+ }
36
+
37
+
38
+ export default function content(str: string) {
39
+ // for CSS entities
40
+ if (str.match(/^_/)) {
41
+ // return '"' + str.split("_").join(" \\").trim() + '"';
42
+ return '"' + str.slice(1).split('_').map(c => '\\' + c).join('') + '"';
43
+ }
44
+
45
+ str = str.replace(/^[-]/, '');
46
+
47
+ // attr() or counter()
48
+ const data = str.match(/^(attr|counter)?[-_]([\w-]+)/);
49
+ if (data) {
50
+ if (data[1] === 'attr') {
51
+ return 'attr(' + data[2] + ')';
52
+ }
53
+ if (data[1] === 'counter') {
54
+ return 'counter(' + data[2] + ')';
55
+ }
56
+ }
57
+
58
+ // return plain string with quotes
59
+ return '"' + str.replace(/[_]/g, ' ') + '"';
60
+ }
61
+ */
@@ -17,17 +17,27 @@ export default function timingFunction(data, custom) {
17
17
  'step-end': 'step-end',
18
18
  };
19
19
  let result = '';
20
- const test1 = /(cubic-bezier|cb)(([-_][-]?[0-9][d.]?[0-9]?){4})/;
21
- const test2 = /(steps|s)[-_]([0-9]+)[-]((jump)?[-]?(start|end|none|both))/;
20
+ // any number of decimals: 0d16, 0d175, 1d56 (before: one digit only, so most real curves failed)
21
+ const test1 = /(cubic-bezier|cb)(([-_][-]?[0-9]+(?:[d.][0-9]+)?){4})/;
22
+ // the position is optional: steps-4 -> steps(4)
23
+ const test2 = /(steps|s)[-_]([0-9]+)(?:[-_]((jump)?[-]?(start|end|none|both)))?/;
22
24
  data.split('__').forEach((e) => {
23
- if (/\b(cubic-bezier|cb)\((-?\d*\.?\d+),(-?\d*\.?\d+),(-?\d*\.?\d+),(-?\d*\.?\d+)\)/.test(e)) {
24
- result = result + e.replace('cb(', 'cubic-bezier(') + ", ";
25
+ // raw functions pass through: cubic-bezier()/cb(), steps(), linear() ("_" is a space)
26
+ if (/^(cubic-bezier|cb|steps|linear)\(.*\)$/.test(e)) {
27
+ result = result + e.replace('cb(', 'cubic-bezier(').replace(/_/g, ' ') + ", ";
25
28
  }
26
29
  else if (test1.test(e)) {
27
- result = result + e.replace(test1, (e, f, g) => 'cubic-bezier' + "(" + g.replace(/-/, "").replace(/--/g, '-Minus').replace(/-/g, ", ").replace(/d/g, ".").replace(/Minus/g, '-') + ")") + ", ";
30
+ result = result + e.replace(test1, (e, f, g) => 'cubic-bezier' + "(" + g.replace(/_/g, '-').replace(/-/, "").replace(/--/g, '-Minus').replace(/-/g, ", ").replace(/d/g, ".").replace(/Minus/g, '-') + ")") + ", ";
28
31
  }
29
32
  else if (test2.test(e)) {
30
- result = result + e.replace(test2, (e, f, g, h) => "steps" + "(" + g + ", " + h + ")") + ", ";
33
+ result = result + e.replace(test2, (e, f, g, h) => {
34
+ if (!h)
35
+ return "steps(" + g + ")";
36
+ // jump-* keywords need the dash: jumpstart / none / both -> jump-start / jump-none / jump-both
37
+ const pos = h.replace(/^jump-?/, '');
38
+ const kw = /^(none|both)$/.test(pos) || /^jump/.test(h) ? 'jump-' + pos : pos;
39
+ return "steps" + "(" + g + ", " + kw + ")";
40
+ }) + ", ";
31
41
  }
32
42
  else if (/^(e|ease|l|linear|ei|ease-in|eo|ease-out|eio|ease-in-out|ss|step-start|se|step-end)$/.test(e)) {
33
43
  result = result + func[e] + ", ";
@@ -36,3 +46,44 @@ export default function timingFunction(data, custom) {
36
46
  if (result.trim())
37
47
  return result.trim().replace(/[,]$/, '');
38
48
  }
49
+ /*
50
+ export default function timingFunction(data: string, custom: { [key: string]: { [key: string]: string } }) {
51
+ data = data.replace(/^[-_]/, '');
52
+
53
+ const func: { [key: string]: string } = {
54
+ e: 'ease',
55
+ ease: 'ease',
56
+ linear: 'linear',
57
+ l: 'linear',
58
+ ei: 'ease-in',
59
+ 'ease-in': 'ease-in',
60
+ eo: 'ease-out',
61
+ 'ease-out': 'ease-out',
62
+ eio: 'ease-in-out',
63
+ 'ease-in-out': 'ease-in-out',
64
+ ss: 'step-start',
65
+ 'step-start': 'step-start',
66
+ se: 'step-end',
67
+ 'step-end': 'step-end',
68
+ };
69
+
70
+ let result:string='';
71
+ const test1=/(cubic-bezier|cb)(([-_][-]?[0-9][d.]?[0-9]?){4})/;
72
+ const test2=/(steps|s)[-_]([0-9]+)[-]((jump)?[-]?(start|end|none|both))/;
73
+ data.split('__').forEach((e)=>{
74
+ if(/\b(cubic-bezier|cb)\((-?\d*\.?\d+),(-?\d*\.?\d+),(-?\d*\.?\d+),(-?\d*\.?\d+)\)/.test(e)){
75
+ result=result+ e.replace('cb(','cubic-bezier(') + ", ";
76
+
77
+ }else if(test1.test(e)){
78
+ result= result+ e.replace(test1,(e,f,g)=>'cubic-bezier'+"("+g.replace(/-/,"").replace(/--/g,'-Minus').replace(/-/g,", ").replace(/d/g,".").replace(/Minus/g,'-')+")") +", ";
79
+ }else if(test2.test(e)){
80
+ result=result+e.replace(test2,(e,f,g,h)=>"steps"+"("+g+", " + h+")")+", ";
81
+ }else if(/^(e|ease|l|linear|ei|ease-in|eo|ease-out|eio|ease-in-out|ss|step-start|se|step-end)$/.test(e)){
82
+ result=result+func[e]+", ";
83
+ }
84
+ })
85
+ if(result.trim()) return result.trim().replace(/[,]$/,'');
86
+
87
+ }
88
+
89
+ */
@@ -7,7 +7,7 @@ export default (value) => {
7
7
  value.split(/__(?=[a-z])/).forEach((e) => {
8
8
  //
9
9
  if (e.match(/[(]/)) {
10
- compileValue += e + " ";
10
+ compileValue += e.replace(/_/g, ' ') + " "; // raw function: "_" is a space
11
11
  return;
12
12
  }
13
13
  // extract function
@@ -21,8 +21,11 @@ export default (value) => {
21
21
  function transformEach(data) {
22
22
  if (data.match(/--[a-z]/)) {
23
23
  const [func, cssVar] = data.split('--');
24
+ // tx--x:8px -> translateX(var(--x,8px))
25
+ const [name, fallback] = cssVar.split(':');
26
+ const fb = fallback !== undefined ? ',' + fallback.replace(/(?<=[0-9])[d](?=[0-9])/g, '.').replace(/(?<=[0-9])p$/, '%') : '';
24
27
  if (tfAlias.hasOwnProperty(func))
25
- return `${tfAlias[func]}(var(--${cssVar}))`;
28
+ return `${tfAlias[func]}(var(--${name}${fb}))`;
26
29
  return;
27
30
  }
28
31
  const match = /([a-zA-z]+(3d)?)(([-]?[-]?[0-9]+[d]?[0-9]*[a-z]*))+/;
@@ -50,51 +53,117 @@ function transformEach(data) {
50
53
  }
51
54
  }
52
55
  const tfAlias = {
53
- m: 'matrix',
54
- matrix: 'matrix',
55
- t: 'translate',
56
- translate: 'translate',
57
- tx: 'translateX',
58
- translateX: 'translateX',
59
- ty: 'translateY',
60
- translateY: 'translateY',
61
- s: 'scale',
62
- scale: 'scale',
63
- sx: 'scaleX',
64
- scaleX: 'scaleX',
65
- sy: 'scaleY',
66
- scaleY: 'scaleY',
67
- r: 'rotate',
68
- rotate: 'rotate',
69
- sk: 'skew',
70
- skew: 'skew',
71
- skx: 'skewX',
72
- skewX: 'skewX',
73
- sky: 'skewY',
74
- skewY: 'skewY',
75
- m3d: 'matrix3d',
76
- matrix3d: 'matrix3d',
77
- t3d: 'translate3d',
78
- translate3d: 'translate3d',
79
- tz: 'translateZ',
80
- translateZ: 'translateZ',
81
- s3d: 'scale3d',
82
- scale3d: 'scale3d',
83
- sz: 'scaleZ',
84
- scaleZ: 'scaleZ',
85
- r3d: 'rotate3d',
86
- rotate3d: 'rotate3d',
87
- rx: 'rotateX',
88
- rotateX: 'rotateX',
89
- ry: 'rotateY',
90
- rotateY: 'rotateY',
91
- rz: 'rotateZ',
92
- rotateZ: 'rotateZ',
93
- p: 'perspective',
94
- perspective: 'perspective',
56
+ m: 'matrix', matrix: 'matrix', t: 'translate', translate: 'translate', tx: 'translateX', translateX: 'translateX',
57
+ ty: 'translateY', translateY: 'translateY', s: 'scale', scale: 'scale', sx: 'scaleX', scaleX: 'scaleX', sy: 'scaleY', scaleY: 'scaleY',
58
+ r: 'rotate', rotate: 'rotate', sk: 'skew', skew: 'skew', skx: 'skewX', skewX: 'skewX', sky: 'skewY', skewY: 'skewY',
59
+ m3d: 'matrix3d', matrix3d: 'matrix3d', t3d: 'translate3d', translate3d: 'translate3d', tz: 'translateZ', translateZ: 'translateZ',
60
+ s3d: 'scale3d', scale3d: 'scale3d', sz: 'scaleZ', scaleZ: 'scaleZ', r3d: 'rotate3d', rotate3d: 'rotate3d',
61
+ rx: 'rotateX', rotateX: 'rotateX', ry: 'rotateY', rotateY: 'rotateY', rz: 'rotateZ', rotateZ: 'rotateZ', p: 'perspective', perspective: 'perspective',
95
62
  };
96
- /* Function values */
97
- const ref = `transform-matrix-1-2-3-4-5-6
63
+ /*
64
+ export default (value:string) => {
65
+ // Remove - before value
66
+ value=value.replace(/^-/,'');
67
+ // initialize compilerValue
68
+
69
+
70
+ let compileValue='';
71
+ // check for multiple value
72
+
73
+ value.split(/__(?=[a-z])/).forEach((e)=>{
74
+ //
75
+ if(e.match(/[(]/)){
76
+ compileValue+=e+" ";
77
+ return
78
+ }
79
+ // extract function
80
+ const result=transformEach(e);
81
+
82
+ if(result) compileValue+= result +" ";
83
+
84
+ })
85
+
86
+ if(compileValue.trim()) return compileValue.trim();
87
+
88
+ }
89
+ function transformEach(data: string) {
90
+ if(data.match(/--[a-z]/)){
91
+ const [func, cssVar]=data.split('--');
92
+ if(tfAlias.hasOwnProperty(func)) return `${tfAlias[func]}(var(--${cssVar}))`
93
+ return ;
94
+
95
+ }
96
+ const match = /([a-zA-z]+(3d)?)(([-]?[-]?[0-9]+[d]?[0-9]*[a-z]*))+/;
97
+ const exfunc = data.match(match);
98
+ let func = null;
99
+ if (exfunc) {
100
+ func = exfunc[1];
101
+ }
102
+ if (!func) return;
103
+ let statement = '';
104
+ if (tfAlias.hasOwnProperty(func)) {
105
+ statement += tfAlias[func] + '(';
106
+ statement +=
107
+ data
108
+ .replace(func, '').replace(/--/g,'-Minus').replace(/^-/,'')
109
+ .replace(/-/g, ', ').replace(/Minus/g,'-')
110
+ .replace(/(?<=[0-9])[d](?=[0-9])/g, '.')
111
+ .replace(/(?<=[0-9])[p](?=[\s|,])/g, '%')
112
+ .replace(/p$/, '%') + ')';
113
+ return statement;
114
+ } else {
115
+ return null;
116
+ }
117
+ }
118
+
119
+ const tfAlias: { [key: string]: string } = {
120
+ m: 'matrix',
121
+ matrix: 'matrix',
122
+ t: 'translate',
123
+ translate: 'translate',
124
+ tx: 'translateX',
125
+ translateX: 'translateX',
126
+ ty: 'translateY',
127
+ translateY: 'translateY',
128
+ s: 'scale',
129
+ scale: 'scale',
130
+ sx: 'scaleX',
131
+ scaleX: 'scaleX',
132
+ sy: 'scaleY',
133
+ scaleY: 'scaleY',
134
+ r: 'rotate',
135
+ rotate: 'rotate',
136
+ sk: 'skew',
137
+ skew: 'skew',
138
+ skx: 'skewX',
139
+ skewX: 'skewX',
140
+ sky: 'skewY',
141
+ skewY: 'skewY',
142
+ m3d: 'matrix3d',
143
+ matrix3d: 'matrix3d',
144
+ t3d: 'translate3d',
145
+ translate3d: 'translate3d',
146
+ tz: 'translateZ',
147
+ translateZ: 'translateZ',
148
+ s3d: 'scale3d',
149
+ scale3d: 'scale3d',
150
+ sz: 'scaleZ',
151
+ scaleZ: 'scaleZ',
152
+ r3d: 'rotate3d',
153
+ rotate3d: 'rotate3d',
154
+ rx: 'rotateX',
155
+ rotateX: 'rotateX',
156
+ ry: 'rotateY',
157
+ rotateY: 'rotateY',
158
+ rz: 'rotateZ',
159
+ rotateZ: 'rotateZ',
160
+ p: 'perspective',
161
+ perspective: 'perspective',
162
+ };
163
+
164
+
165
+ // Function values
166
+ const ref=`transform-matrix-1-2-3-4-5-6
98
167
  transform-matrix3d-1-0-0-0-0-1-0-0-0-0-1-0-0-0-0-1
99
168
  transform-perspective-17px
100
169
  transform-rotate-0.5turn
@@ -116,7 +185,8 @@ transform-skew-30deg-20deg
116
185
  transform-skewX-30deg
117
186
  transform-skewY-1.07rad
118
187
 
119
- /* Multiple function values */
188
+ // Multiple function values
120
189
  transform-translateX-10px--rotate-10deg--translateY-5px
121
190
  transform-perspective-500px--translate-10px-0-20px--rotateY-3deg
122
- `;
191
+ `
192
+ */