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,31 +1,11 @@
1
1
  import color from './color.js';
2
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-]|$)/;
3
+ // A style must be a whole segment ("-s-", "-solid", "-r" at the end). The old lookahead
4
+ // (?=[\w-]|$) let "s"/"r"/"o"/"i"/"g"/"h"/"n" match the start of a colour:
5
+ // b-1px-red -> "1px ridge ed", b-1px-slateTheme7 -> "1px solid" (colour lost).
6
+ const styleRegex = /-(none|n|hidden|h|dotted|dt|dashed|ds|solid|s|double|db|groove|g|ridge|r|inset|i|outset|o)(?=[-_]|$)/;
5
7
  const widthRegex = /[-]?([0-9]+[d/.]?[0-9]*(px|em|fr|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|p))/;
6
8
  let [s, l, c] = ['', '', ''];
7
- // [...data.split('__')].forEach((each)=>{
8
- // // Style
9
- // if(styleRegex.test(data)){
10
- // const m=data.match(styleRegex);
11
- // s=m?style[m[1]]:'';
12
- // data=m?data.replace(m[0],''):data;
13
- // }
14
- // // width
15
- // if(/-(thick|medium|thin)/.test(data)){
16
- // const m=data.match(/-(thick|medium|thin)/);
17
- // l=m?m[1]:'';
18
- // data=m?data.replace(m[0],''):data;
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
- // result= result+`${l?l:''} ${s?s:''} ${c?c:''}`.trim()+
28
- // })
29
9
  // Style
30
10
  if (styleRegex.test(data)) {
31
11
  const m = data.match(styleRegex);
@@ -33,8 +13,8 @@ export default function border(data, custom) {
33
13
  data = m ? data.replace(m[0], '') : data;
34
14
  }
35
15
  // width
36
- if (/-(thick|medium|thin)/.test(data)) {
37
- const m = data.match(/-(thick|medium|thin)/);
16
+ if (/-(thick|medium|thin)(?=[-_]|$)/.test(data)) {
17
+ const m = data.match(/-(thick|medium|thin)(?=[-_]|$)/);
38
18
  l = m ? m[1] : '';
39
19
  data = m ? data.replace(m[0], '') : data;
40
20
  }
@@ -44,7 +24,15 @@ export default function border(data, custom) {
44
24
  data = m ? data.replace(m[0], '') : data;
45
25
  }
46
26
  if (data) {
47
- c = color(data, custom);
27
+ // CSS variable with a fallback colour: --x-border-color:slateTheme6
28
+ const v = data.match(/^-?(--[\w-]+):(.+)$/);
29
+ if (v) {
30
+ const fallback = color(v[2], custom);
31
+ c = `var(${v[1]},${fallback ? fallback : v[2]})`;
32
+ }
33
+ else {
34
+ c = color(data, custom);
35
+ }
48
36
  }
49
37
  return `${l ? l : ''} ${s ? s : ''} ${c ? c : ''}`.trim();
50
38
  }
@@ -70,3 +58,94 @@ const style = {
70
58
  ds: 'dashed',
71
59
  dashed: 'dashed',
72
60
  };
61
+ /*
62
+ import color from './color.js';
63
+ export default function border(data: string, custom: { [key: string]: { [key: string]: string } }) {
64
+
65
+ // let result='';
66
+
67
+ const styleRegex=/-(none|n|hidden|h|dotted|dt|dashed|ds|solid|s|double|db|groove|g|ridge|r|inset|i|outset|o)(?=[\w-]|$)/;
68
+ const widthRegex=/[-]?([0-9]+[d/.]?[0-9]*(px|em|fr|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|p))/;
69
+ let [s,l,c]:[string,string,string|undefined]=['','',''];
70
+
71
+ // [...data.split('__')].forEach((each)=>{
72
+ // // Style
73
+ // if(styleRegex.test(data)){
74
+ // const m=data.match(styleRegex);
75
+ // s=m?style[m[1]]:'';
76
+ // data=m?data.replace(m[0],''):data;
77
+ // }
78
+
79
+ // // width
80
+ // if(/-(thick|medium|thin)/.test(data)){
81
+ // const m=data.match(/-(thick|medium|thin)/);
82
+ // l=m?m[1]:'';
83
+ // data=m?data.replace(m[0],''):data;
84
+
85
+ // }else if(widthRegex.test(data)){
86
+ // const m=data.match(widthRegex);
87
+ // l=m?m[1].replace(/p[\s]?$/,'%').replace(/(\d)d(\d)/,'$1.$2'):'';
88
+ // data=m?data.replace(m[0],''):data;
89
+ // }
90
+
91
+
92
+ // if(data){
93
+ // c=color(data,custom);
94
+ // }
95
+
96
+ // result= result+`${l?l:''} ${s?s:''} ${c?c:''}`.trim()+
97
+
98
+ // })
99
+
100
+
101
+ // Style
102
+ if(styleRegex.test(data)){
103
+ const m=data.match(styleRegex);
104
+ s=m?style[m[1]]:'';
105
+ data=m?data.replace(m[0],''):data;
106
+ }
107
+
108
+ // width
109
+ if(/-(thick|medium|thin)/.test(data)){
110
+ const m=data.match(/-(thick|medium|thin)/);
111
+ l=m?m[1]:'';
112
+ data=m?data.replace(m[0],''):data;
113
+
114
+ }else if(widthRegex.test(data)){
115
+ const m=data.match(widthRegex);
116
+ l=m?m[1].replace(/p[\s]?$/,'%').replace(/(\d)d(\d)/,'$1.$2'):'';
117
+ data=m?data.replace(m[0],''):data;
118
+ }
119
+
120
+
121
+ if(data){
122
+ c=color(data,custom);
123
+ }
124
+
125
+ return `${l?l:''} ${s?s:''} ${c?c:''}`.trim();
126
+
127
+
128
+ }
129
+ const style: { [key: string]: string } = {
130
+ n: 'none',
131
+ none: 'none',
132
+ s: 'solid',
133
+ solid: 'solid',
134
+ r: 'ridge',
135
+ ridge: 'ridge',
136
+ o: 'outset',
137
+ outset: 'outset',
138
+ i: 'inset',
139
+ inset: 'inset',
140
+ h: 'hidden',
141
+ hidden: 'hidden',
142
+ g: 'groove',
143
+ groove: 'groove',
144
+ db: 'double',
145
+ double: 'double',
146
+ dotted: 'dotted',
147
+ dt: 'dotted',
148
+ ds: 'dashed',
149
+ dashed: 'dashed',
150
+ };
151
+ */
@@ -1,8 +1,8 @@
1
1
  export default function clipPath(data, custom) {
2
2
  const valuePortion = data.replace(/^-/, '') || '';
3
- // for raw-css function
3
+ // for raw-css function ("_" is a space, as everywhere else)
4
4
  if (valuePortion.match(/[(]/)) {
5
- return valuePortion;
5
+ return valuePortion.replace(/_/g, ' ');
6
6
  }
7
7
  // const match = /^(path|pa|circle|c|inset|i|polygon|p|ellipse|e|xywh|rect|r)[-]?[\d]/;
8
8
  const match = /^(path|pa|circle|c|inset|i|polygon|p|ellipse|e|xywh|rect|r)[-]?([\d]|-)/;
@@ -25,6 +25,9 @@ export default function clipPath(data, custom) {
25
25
  path: 'path',
26
26
  pa: 'path'
27
27
  };
28
+ // a bare shape: clip-path-circle -> circle()
29
+ if (/^(circle|ellipse)$/.test(valuePortion))
30
+ return valuePortion + '()';
28
31
  if (valuePortion.match(/^(url|u)/)) {
29
32
  shape = 'url';
30
33
  if (valuePortion.replace(/url|u/, '').match(/^--[a-zA-Z]/)) {
@@ -43,13 +46,19 @@ export default function clipPath(data, custom) {
43
46
  }
44
47
  else {
45
48
  content = valuePortion
46
- .replace(extractShape[1], '').replace(/-0-/g, '-0px-')
47
- .replace(/(px|em|p|ex|ch|rem|vw|fr|vh|vmin|vmax|cm|mm|in|pt|pc|cv)/g, '$1 ')
49
+ .replace(extractShape[1], '')
50
+ // every unitless 0 before another value gets a unit, so the "-" before the next number can go:
51
+ // overlapping-safe (inset-0-0-0-0) and at the start of a point (…_0-65p)
52
+ .replace(/(^|[-_])0(?=-)/g, '$10px')
53
+ // longest units first: "pt"/"pc" were read as "p" (= %) + "t"
54
+ .replace(/(px|pt|pc|em|p|ex|ch|rem|vw|fr|vh|vmin|vmax|cm|mm|in|cv)/g, '$1 ')
48
55
  .replace(/p[\s]|p(,)/g, '%$1 ')
49
56
  .replace(/_/g, ', ')
50
57
  .replace('-at', ' at ').replace(/(\d)d(\d)/g, '$1.$2')
51
- .replace('-round', ' round ').replace(/-([0-9][d/.]?[0-9]*)/g, '$1').replace(/[\s][0]px[\s]/g, ' 0 ')
52
- .replace(/^0px[\s]/, '0 ');
58
+ .replace('-round', ' round ').replace(/-([0-9][d/.]?[0-9]*)/g, '$1').replace(/[\s][0]px(?=[\s])/g, ' 0')
59
+ .replace(/^0px[\s]/, '0 ')
60
+ // keywords: "at -center" -> "at center", "-closest-side" -> "closest-side"
61
+ .replace(/(^|\s)-([a-z])/g, '$1$2');
53
62
  }
54
63
  // content=length(valuePortion.replace(extractShape,''));
55
64
  }
@@ -59,3 +68,67 @@ export default function clipPath(data, custom) {
59
68
  }
60
69
  return shape + '(' + content + ')';
61
70
  }
71
+ /*
72
+ export default function clipPath(data: string, custom: { [key: string]: { [key: string]: string } }) {
73
+ const valuePortion: string = data.replace(/^-/, '') || '';
74
+
75
+ // for raw-css function
76
+ if(valuePortion.match(/[(]/)){
77
+ return valuePortion;
78
+
79
+ }
80
+ // const match = /^(path|pa|circle|c|inset|i|polygon|p|ellipse|e|xywh|rect|r)[-]?[\d]/;
81
+ const match = /^(path|pa|circle|c|inset|i|polygon|p|ellipse|e|xywh|rect|r)[-]?([\d]|-)/;
82
+ let shape = null;
83
+ let content = '';
84
+ const shapes: { [key: string]: string } = {
85
+ circle: 'circle',
86
+ c: 'circle',
87
+ inset: 'inset',
88
+ i: 'inset',
89
+ ellipse: 'ellipse',
90
+ e: 'ellipse',
91
+ polygon: 'polygon',
92
+ p: 'polygon',
93
+ rect:'rect',
94
+ r:'rect',
95
+ xywh:'xywh',
96
+ url: 'url',
97
+ u: 'url',
98
+ path:'path',
99
+ pa:'path'
100
+ };
101
+
102
+ if (valuePortion.match(/^(url|u)/)) {
103
+ shape = 'url';
104
+ if(valuePortion.replace(/url|u/, '').match(/^--[a-zA-Z]/)){
105
+ content=`var(${valuePortion.replace(/url|u/, '')})`
106
+ }else{
107
+ content = '#' + valuePortion.replace(/url|u/, '').replace(/^-/, '');
108
+ }
109
+
110
+ } else if (valuePortion.match(match)) {
111
+ const extractShape: RegExpMatchArray | null = valuePortion.match(match);
112
+ if (extractShape) {
113
+ shape = shapes[extractShape[1]];
114
+ if(valuePortion.replace(extractShape[1], '').match(/^--[a-zA-z]/)){
115
+ content=`var(${valuePortion.replace(extractShape[1], '')})`
116
+ }else{
117
+ content = valuePortion
118
+ .replace(extractShape[1], '').replace(/-0-/g,'-0px-')
119
+ .replace(/(px|em|p|ex|ch|rem|vw|fr|vh|vmin|vmax|cm|mm|in|pt|pc|cv)/g, '$1 ')
120
+ .replace(/p[\s]|p(,)/g, '%$1 ')
121
+ .replace(/_/g, ', ')
122
+ .replace('-at', ' at ').replace(/(\d)d(\d)/g,'$1.$2')
123
+ .replace('-round', ' round ').replace(/-([0-9][d/.]?[0-9]*)/g,'$1').replace(/[\s][0]px[\s]/g,' 0 ')
124
+ .replace(/^0px[\s]/,'0 ');
125
+ }
126
+
127
+ // content=length(valuePortion.replace(extractShape,''));
128
+ }
129
+ } else {
130
+ return false;
131
+ }
132
+ return shape + '(' + content + ')';
133
+ }
134
+ */
@@ -1,55 +1,59 @@
1
1
  // custom.color will be provided {primary:'#2d3f3e....}
2
+ //
3
+ // Alpha is read once here and applied once at the end, so every form supports it:
4
+ // names, hex, tokens, variables, 255000000/0.5, rgb-255-0-0/0.5, rgb(1,2,3)/0.5, p3-1-0-0/0.5.
5
+ // (Before, the number/function/p3 forms parsed the alpha and then dropped it.)
2
6
  export default function color(color, custom) {
3
- var _a, _b;
4
- // check for alpha
5
7
  let alpha = null;
6
- // const match=color.match(/\/([0][.][1-9][0-9]?$)/);
7
- const match = color.match(/\/(0\.[0-9][0-9]?|1(\.0+)?)$/);
8
- const matchPercentage = color.match(/\/(100%|[1-9]?[0-9]%)$/);
8
+ // /0.5 /.5 /0.125 /0 /1 /0d5 and percentages /50% /50p
9
+ const match = color.match(/\/(0?\.[0-9]+|0d[0-9]+|0|1(?:\.0+)?)$/);
10
+ const matchPercentage = color.match(/\/(100|[1-9]?[0-9])(%|p)$/);
9
11
  if (match) {
10
- alpha = (_a = match[1]) !== null && _a !== void 0 ? _a : null;
12
+ alpha = match[1].replace('d', '.');
11
13
  color = color.replace(match[0], '');
12
14
  }
13
15
  else if (matchPercentage) {
14
- alpha = (_b = matchPercentage[1]) !== null && _b !== void 0 ? _b : null;
16
+ alpha = matchPercentage[1] + '%';
15
17
  color = color.replace(matchPercentage[0], '');
16
18
  }
19
+ const base = baseColor(color, custom);
20
+ if (base === undefined || alpha === null)
21
+ return base;
22
+ return `oklch(from ${base} l c h/${alpha} )`;
23
+ }
24
+ function baseColor(color, custom) {
17
25
  // ----check for css variables
18
26
  if (color.match(/^--[a-zA-Z]/)) {
19
- if (alpha !== null)
20
- return `oklch(from var(${color}) l c h/${alpha} )`;
27
+ // --brand:red -> var(--brand,red)
28
+ const fb = color.match(/^(--[\w-]+):(.+)$/);
29
+ if (fb) {
30
+ const fallback = baseColor(fb[2], custom);
31
+ return `var(${fb[1]},${fallback !== undefined ? fallback : fb[2]})`;
32
+ }
21
33
  return `var(${color})`;
22
34
  }
23
35
  // remove - before the color
24
36
  color = color.replace(/^[-]/, '');
25
37
  // check if is a raw function
26
38
  if (color.match(/^(rgb|hsl|hsla|rgba|hwb|hwba|lab|oklab|lch|oklch)[(]/)) {
27
- return color.replace(/--([\w][\w-]*)/g, 'var(--$1)');
39
+ return color.replace(/--([\w][\w-]*)/g, 'var(--$1)').replace(/_/g, ' ');
28
40
  }
29
41
  // custom-color
30
42
  if (custom.hasOwnProperty('colors') && typeof custom.colors === 'object') {
31
43
  if (custom.colors.hasOwnProperty(color)) {
32
- if (alpha !== null)
33
- return `oklch(from ${custom.colors[color]} l c h/${alpha} )`;
34
44
  return custom.colors[color];
35
45
  }
36
46
  // custom-color try replacing -
37
47
  if (custom.colors.hasOwnProperty(color.replace(/-/g, ''))) {
38
- if (alpha !== null)
39
- return `oklch(from ${custom.colors[color.replace(/-/g, '')]} l c h/${alpha} )`;
40
48
  return custom.colors[color.replace(/-/g, '')];
41
49
  }
42
50
  }
43
51
  // hexadecimal =+ alpha 00-ff
44
- if (/^[#]?[0-9a-fA-F]{3,8}$/.test(color)) {
45
- if (alpha !== null)
46
- return `oklch(from #${color.replace("#", '')} l c h/${alpha} )`;
52
+ if (/^[#]?([0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(color)) {
47
53
  return `#${color.replace("#", '')}`;
48
54
  // Name
49
55
  }
50
56
  else if (/^[a-zA-Z]+$/.test(color)) {
51
- if (alpha !== null)
52
- return `oklch(from ${color} l c h/${alpha} )`;
53
57
  return color;
54
58
  // rgb/a in number
55
59
  }
@@ -94,8 +98,8 @@ export default function color(color, custom) {
94
98
  }
95
99
  else if (/^p3-/.test(color)) {
96
100
  if (color.replace(/p3/, '').match(/^--/))
97
- return `color(display-p3 var(${color.replace(/p3/, '')})`;
98
- return replaceLast(`color(display-p3 ${color.replace(/p3/, '').replace(/^-/, '').replace(/-/g, ' ').replace('d', '.')
101
+ return `color(display-p3 var(${color.replace(/p3/, '')}))`;
102
+ return replaceLast(`color(display-p3 ${color.replace(/p3/, '').replace(/^-/, '').replace(/-/g, ' ').replace(/([0-9])d([0-9])/g, '$1.$2')
99
103
  .replace(/([0-9])p/g, '$1%')})`, 4, " ", " / ");
100
104
  }
101
105
  else {
@@ -114,3 +118,128 @@ function replaceLast(str, occurs, target, replacement) {
114
118
  return str;
115
119
  }
116
120
  }
121
+ /*
122
+ // custom.color will be provided {primary:'#2d3f3e....}
123
+ export default function color(color: string, custom: { [key: string]: { [key: string]: string } }): string | undefined {
124
+
125
+
126
+ // check for alpha
127
+ let alpha=null;
128
+
129
+ // const match=color.match(/\/([0][.][1-9][0-9]?$)/);
130
+ const match=color.match(/\/(0\.[0-9][0-9]?|1(\.0+)?)$/);
131
+ const matchPercentage=color.match(/\/(100%|[1-9]?[0-9]%)$/);
132
+ if(match){
133
+ alpha = match[1] ?? null;
134
+ color = color.replace(match[0], '');
135
+ }else if(matchPercentage){
136
+ alpha = matchPercentage[1] ?? null;
137
+ color = color.replace(matchPercentage[0], '');
138
+ }
139
+
140
+ // ----check for css variables
141
+
142
+ if(color.match(/^--[a-zA-Z]/)){
143
+ if(alpha!==null) return `oklch(from var(${color}) l c h/${alpha} )`
144
+
145
+ return `var(${color})`
146
+ }
147
+
148
+ // remove - before the color
149
+ color = color.replace(/^[-]/, '');
150
+
151
+ // check if is a raw function
152
+ if(color.match(/^(rgb|hsl|hsla|rgba|hwb|hwba|lab|oklab|lch|oklch)[(]/)){
153
+ return color.replace(/--([\w][\w-]*)/g,'var(--$1)');
154
+ }
155
+
156
+
157
+ // custom-color
158
+ if (custom.hasOwnProperty('colors') && typeof custom.colors === 'object') {
159
+
160
+ if (custom.colors.hasOwnProperty(color)){
161
+ if(alpha!==null) return `oklch(from ${custom.colors[color]} l c h/${alpha} )`
162
+ return custom.colors[color];
163
+ }
164
+
165
+ // custom-color try replacing -
166
+
167
+ if (custom.colors.hasOwnProperty(color.replace(/-/g,''))){
168
+ if(alpha!==null) return `oklch(from ${custom.colors[color.replace(/-/g,'')]} l c h/${alpha} )`
169
+
170
+ return custom.colors[color.replace(/-/g,'')];
171
+
172
+ }
173
+ }
174
+
175
+ // hexadecimal =+ alpha 00-ff
176
+ if (/^[#]?[0-9a-fA-F]{3,8}$/.test(color)) {
177
+ if(alpha!==null) return `oklch(from #${color.replace("#",'')} l c h/${alpha} )`
178
+ return `#${color.replace("#",'')}`;
179
+ // Name
180
+ } else if (/^[a-zA-Z]+$/.test(color)) {
181
+ if(alpha!==null) return `oklch(from ${color} l c h/${alpha} )`
182
+
183
+ return color;
184
+ // rgb/a in number
185
+ } else if (/^[0-9]{9}/.test(color)) {
186
+ if (color.length === 9) return `rgb(${color.replace(/([\d]{3})([\d]{3})([\d]{3})/, '$1,$2,$3')})`;
187
+ else
188
+ return `rgba(${color
189
+ .replace(/([\d]{3})([\d]{3})([\d]{3})([\d]+)/, '$1,$2,$3,$4')
190
+ .replace('d', '.')
191
+ .replace('p', '%')})`;
192
+
193
+ } else if (/^([\d]{3})([\d]{1,3}p)([\d]{1,3}p)/.test(color)) {
194
+ if (/^([\d]{3})([\d]{1,3}p)([\d]{1,3}p)$/.test(color))
195
+ return 'hsl(' + color.replace(/^([\d]{1,3})([\d]{1,3}p)([\d]{1,3}p)/, '$1,$2,$3').replace(/p/g, '%') + ')';
196
+ else
197
+ return (
198
+ 'hsla(' +
199
+ color
200
+ .replace(/^([\d]{1,3})([\d]{1,3}p)([\d]{1,3}p)([\d]+)/, '$1,$2,$3,$4')
201
+ .replace('d', '.')
202
+ .replace(/p/g, '%') +
203
+ ')'
204
+ );
205
+ } else if (/^([\d]{1,3}p)([\d]{1,3}p)([\d]{1,3}p)/.test(color)) {
206
+ if (/^([\d]{1,3}p)([\d]{1,3}p)([\d]{1,3}p$)/.test(color))
207
+ return 'rgb(' + color.replace(/^([\d]{1,3}p)([\d]{1,3}p)([\d]{1,3}p)/, '$1,$2,$3').replace(/p/g, '%') + ')';
208
+ else
209
+ return (
210
+ 'rgba(' +
211
+ color
212
+ .replace(/^([\d]{1,3}p)([\d]{1,3}p)([\d]{1,3}p)([\d]+)/, '$1,$2,$3,$4')
213
+ .replace('d', '.')
214
+ .replace(/p/g, '%') +
215
+ ')'
216
+ );
217
+
218
+
219
+ }else if(/^(rgb|hsl|hsla|rgba|hwb|hwba|lab|oklab|lch|oklch)-/.test(color)){
220
+ const match=color.match(/^(rgb|hsl|hsla|rgba|hwb|hwba|lab|oklab|lch|oklch)-/);
221
+ const colorFunc=match?match[1]:'';
222
+ if(color.replace(colorFunc,'').match(/^--/)) return `${colorFunc}(var(${color.replace(colorFunc,'')}))`
223
+ return replaceLast(`${colorFunc}(${color.replace(colorFunc,'').replace(/^-/,'').replace(/-/g,' ').replace(/([0-9])d([0-9])/g, '$1.$2')
224
+ .replace(/p/g, '%')})`, 3," "," / ");
225
+
226
+
227
+ }else if(/^p3-/.test(color)){
228
+ if(color.replace(/p3/,'').match(/^--/)) return `color(display-p3 var(${color.replace(/p3/,'')})`
229
+ return replaceLast(`color(display-p3 ${color.replace(/p3/,'').replace(/^-/,'').replace(/-/g,' ').replace('d', '.')
230
+ .replace(/([0-9])p/g, '$1%')})`, 4," "," / ");
231
+ } else {
232
+ return;
233
+ }
234
+ }
235
+
236
+ function replaceLast(str:string, occurs:number, target:string, replacement:string) {
237
+ if(str.match(new RegExp(target,'g'))?.length===occurs){
238
+ const lastIndex = str.lastIndexOf(target);
239
+ if (lastIndex === -1) return str;
240
+ return str.slice(0, lastIndex) + replacement + str.slice(lastIndex + target.length);
241
+ }else{
242
+ return str;
243
+ }
244
+ }
245
+ */
@@ -1,7 +1,8 @@
1
1
  import shadow from './shadow.js';
2
2
  export default function filter(valuePortion, custom) {
3
3
  let compileValue = '';
4
- const matchRegEx = /^[-]?([a-zA-Z]+([-][\w]+)?)(?=[-])/;
4
+ // second word must start with a letter (hue-rotate, drop-shadow): with [\w]+ "ds-0-4px…" read "ds-0" as the name
5
+ const matchRegEx = /^[-]?([a-zA-Z]+([-][a-zA-Z]+)?)(?=[-])/;
5
6
  valuePortion.split(/__/).forEach((each) => {
6
7
  var _a;
7
8
  // check for raw-css funcion
@@ -14,7 +15,10 @@ export default function filter(valuePortion, custom) {
14
15
  if (each.match(/--[a-zA-Z]/)) {
15
16
  const [functionPortion, functionValuePortion] = [(_a = each.split(/--/)[0]) === null || _a === void 0 ? void 0 : _a.replace(/^-/, ''), each.split(/--/)[1]];
16
17
  if (funcAlias.hasOwnProperty(functionPortion)) {
17
- compileValue += `${functionPortion}(var(--${functionValuePortion})) `;
18
+ // b--x -> blur(var(--x)), not b(var(--x)); b--x:4px -> blur(var(--x,4px))
19
+ const [name, fallback] = functionValuePortion.split(':');
20
+ const fb = fallback !== undefined ? ',' + number(fallback) : '';
21
+ compileValue += `${funcAlias[functionPortion]}(var(--${name}${fb})) `;
18
22
  return;
19
23
  }
20
24
  }
@@ -28,13 +32,20 @@ export default function filter(valuePortion, custom) {
28
32
  value = value ? value : '';
29
33
  }
30
34
  else {
31
- value = each.replace(matchRegEx, '').replace(/-(-)?/g, '$1').replace(/p$/, '%').replace(/(?<=[0-9])[d](?=[0-9])/, '.');
35
+ value = number(each.replace(matchRegEx, ''));
32
36
  }
33
37
  }
38
+ // unknown function or no value: leave it out instead of writing "(4px)" or "()"
39
+ if (!fn || !value)
40
+ return;
34
41
  compileValue += `${fn}(${value}) `;
35
42
  });
36
43
  return compileValue.replace(/[\s]$/, '');
37
44
  }
45
+ // -1d5 -> 1.5, -50p -> 50%, --90deg -> -90deg (every decimal, not just the first)
46
+ function number(v) {
47
+ return v.replace(/-(-)?/g, '$1').replace(/p$/, '%').replace(/(?<=[0-9])[d](?=[0-9])/g, '.');
48
+ }
38
49
  const funcAlias = {
39
50
  b: 'blur',
40
51
  blur: 'blur',
@@ -57,3 +68,79 @@ const funcAlias = {
57
68
  se: 'sepia',
58
69
  sepia: 'sepia',
59
70
  };
71
+ /*
72
+ import shadow from './shadow.js';
73
+
74
+ type Custom = { [key: string]: { [key: string]: string } };
75
+
76
+ export default function filter(valuePortion: string, custom: Custom) {
77
+ let compileValue='';
78
+ const matchRegEx=/^[-]?([a-zA-Z]+([-][\w]+)?)(?=[-])/;
79
+ valuePortion.split(/__/).forEach((each)=>{
80
+ // check for raw-css funcion
81
+ if(each.match(/[(]/)){
82
+ compileValue+=each.replace(/^-/,'')+" ";
83
+ return;
84
+ }
85
+
86
+
87
+ let [fn,value]=['',''];
88
+ // css-var
89
+ if(each.match(/--[a-zA-Z]/)){
90
+ const [functionPortion,functionValuePortion]:[string,string]=[each.split(/--/)[0]?.replace(/^-/,''),each.split(/--/)[1]];
91
+
92
+ if(funcAlias.hasOwnProperty(functionPortion)){
93
+
94
+ compileValue+=`${functionPortion}(var(--${functionValuePortion})) `
95
+ return
96
+ }
97
+ }
98
+
99
+ const extractFnV = each.match(matchRegEx);
100
+
101
+ if(extractFnV){
102
+ if(funcAlias.hasOwnProperty(extractFnV[1])){
103
+ fn=funcAlias[extractFnV[1]];
104
+ }
105
+
106
+ if(fn==='drop-shadow'){
107
+ value=shadow(each.replace(matchRegEx,''),custom)
108
+ value=value?value:''
109
+ }else{
110
+ value=each.replace(matchRegEx,'').replace(/-(-)?/g,'$1').replace(/p$/, '%').replace(/(?<=[0-9])[d](?=[0-9])/, '.');
111
+ }
112
+ }
113
+
114
+ compileValue+= `${fn}(${value}) `;
115
+
116
+
117
+
118
+
119
+ })
120
+
121
+ return compileValue.replace(/[\s]$/, '');
122
+ }
123
+
124
+ const funcAlias: { [key: string]: string } = {
125
+ b: 'blur',
126
+ blur: 'blur',
127
+ br: 'brightness',
128
+ brightness: 'brightness',
129
+ 'drop-shadow': 'drop-shadow',
130
+ ds: 'drop-shadow',
131
+ c: 'contrast',
132
+ contrast: 'contrast',
133
+ g: 'grayscale',
134
+ grayscale: 'grayscale',
135
+ hr: 'hue-rotate',
136
+ 'hue-rotate': 'hue-rotate',
137
+ i: 'invert',
138
+ invert: 'invert',
139
+ o: 'opacity',
140
+ opacity: 'opacity',
141
+ saturate: 'saturate',
142
+ s: 'saturate',
143
+ se: 'sepia',
144
+ sepia: 'sepia',
145
+ };
146
+ */
@@ -2,18 +2,46 @@ export default function font(font, custom) {
2
2
  font = font.replace(/^[-_]/, '');
3
3
  let holder = '';
4
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 + ', ';
5
+ // CSS variable, with an optional fallback family: --x-font / --x-font:Segoe_UI
6
+ // (before, "--x-font" became a font *named* --x-font: valid CSS, so nothing warned)
7
+ const v = e.match(/^(--[a-zA-Z][\w-]*)(?::(.+))?$/);
8
+ if (v) {
9
+ holder += `var(${v[1]}${v[2] ? ',' + family(v[2], custom) : ''}), `;
10
+ return;
16
11
  }
12
+ holder += family(e, custom) + ', ';
17
13
  });
18
14
  return holder.replace(/,[\s]$/, '');
19
15
  }
16
+ // One family: a custom font alias, "Quoted Name" when it has spaces (_), or as written
17
+ function family(e, custom) {
18
+ if (custom.hasOwnProperty('font') && typeof custom.font === 'object' && custom.font.hasOwnProperty(e)) {
19
+ return custom.font[e];
20
+ }
21
+ if (e.search(/_/) !== -1)
22
+ return '"' + e.replace(/_/g, ' ') + '"';
23
+ return e;
24
+ }
25
+ /*
26
+ export default function font(font: string, custom: { [key: string]: { [key: string]: string } }): string {
27
+ font = font.replace(/^[-_]/, '');
28
+
29
+ let holder = '';
30
+
31
+ font.split(/__/).forEach((e) => {
32
+ if (custom.hasOwnProperty('font') && typeof custom.font === 'object') {
33
+ if (custom.font.hasOwnProperty(e)){
34
+ holder+= custom.font[e]+ ', ';
35
+ return;
36
+ }
37
+ }
38
+ if (e.search(/_/) !== -1) {
39
+ holder += '"' + e.replace(/_/g, ' ') + '", ';
40
+ } else {
41
+ holder += e + ', ';
42
+ }
43
+ });
44
+
45
+ return holder.replace(/,[\s]$/, '');
46
+ }
47
+ */