aliascss 1.3.9 → 1.4.0

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.
@@ -1,5 +1,5 @@
1
1
  const element = {
2
- test: /^_[_]?[A-Za-z0-9_\.,]+(?=[_[-])/,
2
+ test: /^_[_]?[A-Za-z0-9_\.,]+(?=[@_[-])/,
3
3
  process(className) {
4
4
  const match = className.match(this.test);
5
5
  if (match) {
@@ -2,6 +2,7 @@
2
2
  import pseudoSelector from './pseudoSelectorNew.js';
3
3
  import elementSelector from './element-selector.js';
4
4
  import attribute from './attribute-selector.js';
5
+ import fallbackSelector from './fallback-selector.js';
5
6
  export default function extractPrefix(className) {
6
7
  let workingClassName = className;
7
8
  let result = '';
@@ -58,6 +59,24 @@ export default function extractPrefix(className) {
58
59
  workingClassName = replacedClassName;
59
60
  match = true;
60
61
  }
62
+ else if (fallbackSelector.test.test(workingClassName)) {
63
+ console.log('=-=-=-=-=-=--=', workingClassName);
64
+ const [replacedClassName, selector] = fallbackSelector.process(workingClassName);
65
+ if (result.match(/:(not|where|has|is)[)]?$/)) {
66
+ const m = result.match(/:(not|where|has|is)([)])?$/);
67
+ if (m === null || m === void 0 ? void 0 : m[2]) {
68
+ result = result.replace(/\)$/, '') + `(${selector}))`;
69
+ }
70
+ else {
71
+ result += `(${selector})`;
72
+ }
73
+ }
74
+ else {
75
+ result += selector;
76
+ }
77
+ workingClassName = replacedClassName;
78
+ match = true;
79
+ }
61
80
  else {
62
81
  match = false;
63
82
  }
@@ -0,0 +1,5 @@
1
+ declare const fallbackSelector: {
2
+ [key: string]: any;
3
+ process: (...args: any[]) => any;
4
+ };
5
+ export default fallbackSelector;
@@ -0,0 +1,14 @@
1
+ const fallbackSelector = {
2
+ test: /^[-,_]?[_]?@(selector)?\(((?:[^()]+|\((?:[^()]+|\([^()]*\))*\))*)\)/, // @(selector)?\(((?:[^()]+|\((?:[^()]+|\([^()]*\))*\))*)\)
3
+ process(className) {
4
+ const match = className.match(this.test);
5
+ if (match) {
6
+ const selector = match[0];
7
+ if (selector) {
8
+ const result = match[2];
9
+ return [className.replace(selector, ''), /^[_]/.test(className) ? ' ' + result : result];
10
+ }
11
+ }
12
+ }
13
+ };
14
+ export default fallbackSelector;
@@ -9,23 +9,31 @@
9
9
  */
10
10
  export default function getPropertyAndValue(className, cssPropertiesWithAlias, staticClassNames, custom, extractProperty, // (a:string,b:{[key:string]:Property})=>[Property,string],
11
11
  bool = false) {
12
+ var _a;
12
13
  // Case 1 StaticClassNames
13
14
  if (staticClassNames.hasOwnProperty(className)) {
14
15
  return staticClassNames[className];
15
16
  }
16
- // case CSS define var
17
+ // case 2 defining css-variable as className
17
18
  if (className.startsWith('--') && className.includes(':')) {
18
19
  let value = className.slice(className.indexOf(':')).replace(':', '');
19
20
  const property = className.replace(value, '').replace(':', '');
20
- const possiblePropsName = property.slice(property.lastIndexOf('-') + 1);
21
+ let possiblePropsName = '';
22
+ const camelCasePropertyHint = (_a = property.match(/[A-Z][a-z0-9]*$/)) === null || _a === void 0 ? void 0 : _a[0];
23
+ if (camelCasePropertyHint) {
24
+ possiblePropsName = camelCasePropertyHint.toLowerCase();
25
+ }
26
+ else {
27
+ possiblePropsName = property.slice(property.lastIndexOf('-') + 1);
28
+ }
21
29
  let compiler = null;
22
30
  if (cssPropertiesWithAlias.hasOwnProperty(possiblePropsName) && cssPropertiesWithAlias[possiblePropsName].hasOwnProperty('compiler') && typeof cssPropertiesWithAlias[possiblePropsName].compiler === 'function') {
23
31
  compiler = cssPropertiesWithAlias[possiblePropsName].compiler;
24
32
  }
25
- // New Case :()
26
- // check if has :()
33
+ // if value is function i.e --some-var:(12px,red,blue);
27
34
  if (/^\(.+\)[_]?$/.test(value)) {
28
35
  if (value.match(/_$/)) {
36
+ // replace --[name] with var(--[name])
29
37
  const val = value.replace(/(--[\w-]+)/g, 'var($1)')
30
38
  .replace(/^[(]/, '').replace(/_$/, '').replace(/[)]$/, '')
31
39
  .replace(/,/g, ', ');
@@ -55,6 +63,9 @@ bool = false) {
55
63
  }
56
64
  return bool ? [property, "var(" + cssVar + ',' + val + ')'] : property + ": var(" + cssVar + ',' + val + ')';
57
65
  }
66
+ else if (compiler && compiler.name === 'color') {
67
+ return bool ? [property, compiler(value)] : property + ":" + compiler(value);
68
+ }
58
69
  return bool ? [property, "var(" + value + ')'] : property + ": var(" + value + ')';
59
70
  }
60
71
  else {
@@ -81,17 +92,9 @@ bool = false) {
81
92
  .replace(/[\s](mix|cmyk|set|gradient|bezier|content|shadow|rotate|dark|conic|linear|radial)/g, '-$1');
82
93
  }
83
94
  return bool ? [property, value] : property + ":" + value;
84
- // return bool?[property,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,' / ')
85
- // .replace(/auto flow/g,'auto-flow').replace(/__/g," ")
86
- // .replace(/[\s](mix|cmyk|set|gradient|bezier|content|shadow|rotate|dark|conic|linear|radial)/g,'-$1')
87
- // ]
88
- // :
89
- // property+":"+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,' / ')
90
- // .replace(/auto flow/g,'auto-flow')
91
- // .replace(/__/g," ")
92
- // .replace(/[\s](mix|cmyk|set|gradient|bezier|content|shadow|rotate|dark|conic|linear|radial)/g,'-$1');
93
95
  }
94
96
  }
97
+ // End of CSS-variable as a className
95
98
  const [property, propertyKey] = extractProperty(className, cssPropertiesWithAlias);
96
99
  // console.log(propertyKey,'ttt',property,className)
97
100
  if (property) {
@@ -177,6 +180,12 @@ bool = false) {
177
180
  }
178
181
  return bool ? [prop, "var(" + cssVar + ',' + value + ')'] : prop + ": var(" + cssVar + ',' + value + ')';
179
182
  }
183
+ if (/(background|color)$/.test(prop)) {
184
+ if (cssPropertiesWithAlias.color.compiler && typeof cssPropertiesWithAlias.color.compiler === 'function') {
185
+ const value = cssPropertiesWithAlias.color.compiler(valuePortion, custom);
186
+ return bool ? [prop, value] : prop + ":" + value;
187
+ }
188
+ }
180
189
  return bool ? [prop, "var(" + valuePortion + ')'] : prop + ": var(" + valuePortion + ')';
181
190
  }
182
191
  if (property.hasOwnProperty('compiler') && typeof property.compiler === 'function') {
@@ -170,6 +170,7 @@ export const customStaticClassNames = {
170
170
  'x-absolute-inset-y': "position:absolute;margin:auto;top:0;bottom:0;",
171
171
  'x-absolute-inset-x': "position:absolute;left:0;right:0;",
172
172
  'x-fixed-center': "position:fixed;margin:auto;top:0;left:0;right:0;bottom:0;",
173
+ 'x-isolate': 'isolation:isolate',
173
174
  'x-sr-only': 'position:absolute;overflow:hidden;clip-path:rect(0 0 0 0);height:1px;width:1px;margin:-1px;padding:0;border:0',
174
175
  // 'x-jusitfy-between':'justify-content: space-between',
175
176
  // 'x-flex':'display:flex',
@@ -0,0 +1,3 @@
1
+ export declare const staticClassNamesAlias: {
2
+ [key: string]: string;
3
+ };