@master/css 2.0.0-rc.26 → 2.0.0-rc.27

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 (84) hide show
  1. package/dist/common.cjs +124 -0
  2. package/dist/common.d.ts +22 -0
  3. package/dist/common.mjs +106 -0
  4. package/dist/config/functions.cjs +40 -41
  5. package/dist/config/functions.mjs +39 -40
  6. package/dist/config/index.cjs +3 -3
  7. package/dist/config/index.d.ts +9 -10
  8. package/dist/config/index.mjs +3 -3
  9. package/dist/config/queries.cjs +4 -0
  10. package/dist/config/queries.d.ts +4 -0
  11. package/dist/config/queries.mjs +4 -0
  12. package/dist/config/rules.cjs +964 -851
  13. package/dist/config/rules.d.ts +8 -5
  14. package/dist/config/rules.mjs +966 -852
  15. package/dist/config/selectors.cjs +0 -1
  16. package/dist/config/selectors.d.ts +0 -1
  17. package/dist/config/selectors.mjs +0 -1
  18. package/dist/config/{semantics.cjs → utilities.cjs} +2 -5
  19. package/dist/config/{semantics.d.ts → utilities.d.ts} +2 -5
  20. package/dist/config/{semantics.mjs → utilities.mjs} +2 -5
  21. package/dist/core.cjs +192 -132
  22. package/dist/core.d.ts +18 -14
  23. package/dist/core.mjs +193 -133
  24. package/dist/index.cjs +36 -16
  25. package/dist/index.d.ts +13 -8
  26. package/dist/index.mjs +14 -11
  27. package/dist/layer.cjs +25 -20
  28. package/dist/layer.d.ts +26 -9
  29. package/dist/layer.mjs +22 -19
  30. package/dist/rule.cjs +43 -49
  31. package/dist/rule.d.ts +37 -24
  32. package/dist/rule.mjs +43 -49
  33. package/dist/utils/generate-css.cjs +13 -0
  34. package/dist/utils/generate-css.d.ts +2 -0
  35. package/dist/utils/generate-css.mjs +11 -0
  36. package/dist/utils/hex-to-rgb.cjs +1 -1
  37. package/dist/utils/hex-to-rgb.d.ts +1 -1
  38. package/dist/utils/hex-to-rgb.mjs +1 -1
  39. package/dist/utils/is-core-rule.cjs +9 -0
  40. package/dist/utils/is-core-rule.d.ts +1 -0
  41. package/dist/utils/is-core-rule.mjs +7 -0
  42. package/dist/{functions → utils}/reorder-for-readable-classes.cjs +5 -11
  43. package/dist/{functions → utils}/reorder-for-readable-classes.d.ts +1 -5
  44. package/dist/{functions → utils}/reorder-for-readable-classes.mjs +6 -12
  45. package/package.json +1 -1
  46. package/dist/constants/base-unit-regex.cjs +0 -5
  47. package/dist/constants/base-unit-regex.d.ts +0 -1
  48. package/dist/constants/base-unit-regex.mjs +0 -3
  49. package/dist/constants/start-symbol.cjs +0 -10
  50. package/dist/constants/start-symbol.d.ts +0 -6
  51. package/dist/constants/start-symbol.mjs +0 -8
  52. package/dist/utils/concat-arrays.cjs +0 -12
  53. package/dist/utils/concat-arrays.d.ts +0 -1
  54. package/dist/utils/concat-arrays.mjs +0 -10
  55. package/dist/utils/get-type.cjs +0 -12
  56. package/dist/utils/get-type.d.ts +0 -7
  57. package/dist/utils/get-type.mjs +0 -10
  58. package/dist/utils/is-plain-object.cjs +0 -15
  59. package/dist/utils/is-plain-object.d.ts +0 -8
  60. package/dist/utils/is-plain-object.mjs +0 -13
  61. package/dist/utils/is-symbol.cjs +0 -14
  62. package/dist/utils/is-symbol.d.ts +0 -7
  63. package/dist/utils/is-symbol.mjs +0 -12
  64. package/dist/utils/rgb-to-hex.cjs +0 -7
  65. package/dist/utils/rgb-to-hex.d.ts +0 -1
  66. package/dist/utils/rgb-to-hex.mjs +0 -5
  67. /package/dist/{functions → utils}/are-rule-modes-equal.cjs +0 -0
  68. /package/dist/{functions → utils}/are-rule-modes-equal.d.ts +0 -0
  69. /package/dist/{functions → utils}/are-rule-modes-equal.mjs +0 -0
  70. /package/dist/{functions → utils}/are-rule-queries-equal.cjs +0 -0
  71. /package/dist/{functions → utils}/are-rule-queries-equal.d.ts +0 -0
  72. /package/dist/{functions → utils}/are-rule-queries-equal.mjs +0 -0
  73. /package/dist/{functions → utils}/are-rule-selectors-equal.cjs +0 -0
  74. /package/dist/{functions → utils}/are-rule-selectors-equal.d.ts +0 -0
  75. /package/dist/{functions → utils}/are-rule-selectors-equal.mjs +0 -0
  76. /package/dist/{functions → utils}/are-rule-states-equal.cjs +0 -0
  77. /package/dist/{functions → utils}/are-rule-states-equal.d.ts +0 -0
  78. /package/dist/{functions → utils}/are-rule-states-equal.mjs +0 -0
  79. /package/dist/{functions → utils}/are-rules-duplicated.cjs +0 -0
  80. /package/dist/{functions → utils}/are-rules-duplicated.d.ts +0 -0
  81. /package/dist/{functions → utils}/are-rules-duplicated.mjs +0 -0
  82. /package/dist/{functions → utils}/extend-config.cjs +0 -0
  83. /package/dist/{functions → utils}/extend-config.d.ts +0 -0
  84. /package/dist/{functions → utils}/extend-config.mjs +0 -0
package/dist/rule.d.ts CHANGED
@@ -1,16 +1,15 @@
1
1
  import MasterCSS, { type Variable } from './core';
2
- import { Layer } from './layer';
2
+ import Layer from './layer';
3
3
  import { type PropertiesHyphen } from 'csstype';
4
4
  export declare class Rule {
5
5
  readonly className: string;
6
+ readonly RegisteredRule: RegisteredRule;
6
7
  css: MasterCSS;
7
8
  readonly at: Record<string, AtComponent[]>;
8
9
  readonly priority: number;
9
10
  readonly natives: NativeRule[];
10
11
  readonly order: number;
11
12
  readonly layer: Layer;
12
- readonly atToken: string;
13
- readonly stateToken: string;
14
13
  readonly declarations?: PropertiesHyphen;
15
14
  animationNames?: string[];
16
15
  variableNames?: string[];
@@ -18,20 +17,22 @@ export declare class Rule {
18
17
  resolveAtComponent(atComponent: AtComponent): string;
19
18
  resolveValue: (valueComponents: ValueComponent[], unit: string, bypassVariableNames: string[], bypassParsing: boolean) => string;
20
19
  get text(): string;
21
- parseValue: (currentValueComponents: ValueComponent[], i: number, value: string, unit: string, endSymbol: string, parentFunctionName?: string, bypassParsing?: boolean, bypassVariableNames?: string[]) => number;
22
- parseValueComponent(token: string | number, unit?: any): StringValueComponent | NumericValueComponent;
20
+ parseValues: (currentValueComponents: ValueComponent[], i: number, value: string, unit: string, endSymbol: string, parentFunctionName?: string, bypassParsing?: boolean, bypassVariableNames?: string[]) => number;
21
+ parseValue(token: string | number, unit?: any): {
22
+ value: string;
23
+ type: 'string';
24
+ } | {
25
+ value: number;
26
+ unit: string;
27
+ type: 'number';
28
+ };
23
29
  }
24
- export type AtComponent = AtArbitraryComponent | AtMediaTypeComponent | AtFeatureComponent | AtOperatorComponent;
30
+ export type AtComponent = AtArbitraryComponent | AtFeatureComponent | AtOperatorComponent;
25
31
  export interface AtArbitraryComponent {
26
32
  type: 'arbitrary';
27
33
  token?: string;
28
34
  value: string;
29
35
  }
30
- export interface AtMediaTypeComponent {
31
- type: 'media-type';
32
- token?: string;
33
- value: 'all' | 'print' | 'screen' | 'speech';
34
- }
35
36
  export interface AtFeatureComponent {
36
37
  type: 'feature';
37
38
  token?: string;
@@ -48,20 +49,20 @@ export interface AtOperatorComponent {
48
49
  export type ValueComponent = StringValueComponent | NumericValueComponent | FunctionValueComponent | VariableValueComponent | SeparatorValueComponent;
49
50
  export interface StringValueComponent {
50
51
  text?: string;
51
- token?: string;
52
+ token: string;
52
53
  type: 'string';
53
54
  value: string;
54
55
  }
55
56
  export interface NumericValueComponent {
56
57
  text?: string;
57
- token?: string;
58
+ token: string;
58
59
  type: 'number';
59
60
  value: number;
60
61
  unit?: string;
61
62
  }
62
63
  export interface FunctionValueComponent {
63
64
  text?: string;
64
- token?: string;
65
+ token: string;
65
66
  type: 'function';
66
67
  name: string;
67
68
  symbol: string;
@@ -70,7 +71,7 @@ export interface FunctionValueComponent {
70
71
  }
71
72
  export interface VariableValueComponent {
72
73
  text?: string;
73
- token?: string;
74
+ token: string;
74
75
  type: 'variable';
75
76
  name: string;
76
77
  alpha?: string;
@@ -79,12 +80,11 @@ export interface VariableValueComponent {
79
80
  }
80
81
  export interface SeparatorValueComponent {
81
82
  text?: string;
83
+ token: string;
82
84
  type: 'separator';
83
85
  value: string;
84
86
  }
85
87
  export interface Rule extends RegisteredRule {
86
- colored: boolean;
87
- prefix: string;
88
88
  token: string;
89
89
  vendorPrefixSelectors: Record<string, string[]>;
90
90
  vendorSuffixSelectors: Record<string, string[]>;
@@ -92,27 +92,40 @@ export interface Rule extends RegisteredRule {
92
92
  direction: string;
93
93
  mode: string;
94
94
  unitToken: string;
95
+ keyToken: string;
96
+ valueToken: string;
97
+ stateToken: string;
98
+ atToken: string;
95
99
  hasWhere: boolean;
96
100
  valueComponents: Array<ValueComponent>;
97
101
  }
98
102
  export interface RegisteredRule {
99
103
  id: string;
100
- match?: RegExp;
101
- variables?: any;
104
+ key?: string;
105
+ keys: string[];
106
+ matchers: {
107
+ key?: RegExp;
108
+ variable?: RegExp;
109
+ value?: RegExp;
110
+ arbitrary?: RegExp;
111
+ };
112
+ variables: Record<string, Variable>;
102
113
  order: number;
103
114
  definition: RuleDefinition;
104
115
  }
105
116
  export interface RuleDefinition {
106
117
  layer?: Layer;
107
- match?: RegExp | [string, string[]?];
118
+ matcher?: RegExp;
119
+ sign?: string;
120
+ key?: string;
121
+ subkey?: string;
122
+ ambiguousKeys?: string[];
123
+ ambiguousValues?: (RegExp | string)[];
108
124
  variables?: string[];
109
125
  separators?: string[];
110
- shorthand?: string;
111
- colored?: boolean;
112
- numeric?: boolean;
113
126
  unit?: any;
114
- native?: boolean;
115
127
  declarations?: PropertiesHyphen;
128
+ includeAnimations?: boolean;
116
129
  analyze?: (this: Rule, className: string) => [valueToken: string, prefixToken?: string];
117
130
  transformValue?(this: Rule, value: string): string;
118
131
  transformValueComponents?(this: Rule, valueComponents: ValueComponent[]): ValueComponent[];
package/dist/rule.mjs CHANGED
@@ -1,30 +1,28 @@
1
- import { START_SYMBOLS } from './constants/start-symbol.mjs';
2
1
  import cssEscape from './shared/utils/css-escape.mjs';
3
- import { Layer } from './layer.mjs';
4
- import { BASE_UNIT_REGEX } from './constants/base-unit-regex.mjs';
2
+ import Layer from './layer.mjs';
3
+ import { VALUE_DELIMITERS, UNIT_REGEX, BASE_UNIT_REGEX } from './common.mjs';
5
4
 
6
5
  class Rule {
7
6
  className;
7
+ RegisteredRule;
8
8
  css;
9
9
  at;
10
10
  priority;
11
11
  natives;
12
12
  order;
13
13
  layer;
14
- atToken;
15
- stateToken;
16
14
  declarations;
17
15
  animationNames;
18
16
  variableNames;
19
17
  constructor(className, RegisteredRule, css){
20
18
  this.className = className;
19
+ this.RegisteredRule = RegisteredRule;
21
20
  this.css = css;
22
21
  this.at = {};
23
22
  this.priority = -1;
24
23
  this.natives = [];
25
24
  this.order = 0;
26
25
  this.layer = 0;
27
- this.atToken = '';
28
26
  this.resolveValue = (valueComponents, unit, bypassVariableNames, bypassParsing)=>{
29
27
  const { functions } = this.css.config;
30
28
  let currentValue = '';
@@ -35,12 +33,12 @@ class Rule {
35
33
  const functionDefinition = functions && functions[eachValueComponent.name];
36
34
  if (functionDefinition?.transform && !eachValueComponent.bypassTransform) {
37
35
  const result = functionDefinition.transform.call(this, this.resolveValue(eachValueComponent.children, functionDefinition.unit ?? unit, bypassVariableNames, bypassParsing || eachValueComponent.name === 'calc'), bypassVariableNames);
38
- currentValue += eachValueComponent.text = typeof result === 'string' ? result : this.resolveValue(result, functionDefinition?.unit ?? unit, bypassVariableNames, bypassParsing);
36
+ currentValue += eachValueComponent.token = eachValueComponent.text = typeof result === 'string' ? result : this.resolveValue(result, functionDefinition?.unit ?? unit, bypassVariableNames, bypassParsing);
39
37
  } else {
40
- currentValue += eachValueComponent.text = eachValueComponent.name + eachValueComponent.symbol + this.resolveValue(eachValueComponent.children, functionDefinition?.unit ?? unit, bypassVariableNames, bypassParsing) + START_SYMBOLS[eachValueComponent.symbol];
38
+ currentValue += eachValueComponent.token = eachValueComponent.text = eachValueComponent.name + eachValueComponent.symbol + this.resolveValue(eachValueComponent.children, functionDefinition?.unit ?? unit, bypassVariableNames, bypassParsing) + VALUE_DELIMITERS[eachValueComponent.symbol];
41
39
  }
42
40
  break;
43
- // todo: 應挪到 parseValue 階段處理才能支援 variables: { x: 'calc(20vw-30px)' } 這種情況,並且解析上可能會比較合理、精簡
41
+ // todo: 應挪到 parseValues 階段處理才能支援 variables: { x: 'calc(20vw-30px)' } 這種情況,並且解析上可能會比較合理、精簡
44
42
  case 'variable':
45
43
  // eslint-disable-next-line no-case-declarations
46
44
  const variable = this.css.variables[eachValueComponent.name];
@@ -69,7 +67,7 @@ class Rule {
69
67
  case 'string':
70
68
  handleVariable((variable)=>{
71
69
  const valueComponents = [];
72
- this.parseValue(valueComponents, 0, variable.value, unit, '', undefined, bypassParsing, [
70
+ this.parseValues(valueComponents, 0, variable.value, unit, '', undefined, bypassParsing, [
73
71
  ...bypassVariableNames,
74
72
  eachValueComponent.name
75
73
  ]);
@@ -84,9 +82,9 @@ class Rule {
84
82
  case 'number':
85
83
  handleVariable((variable)=>{
86
84
  if (bypassParsing) {
87
- currentValue += eachValueComponent.text = variable.value;
85
+ currentValue += eachValueComponent.text = String(variable.value);
88
86
  } else {
89
- const valueComponent = this.parseValueComponent(variable.value, unit);
87
+ const valueComponent = this.parseValue(variable.value, unit);
90
88
  currentValue += eachValueComponent.text = valueComponent.value + (valueComponent.unit ?? '');
91
89
  }
92
90
  }, ()=>{
@@ -120,7 +118,7 @@ class Rule {
120
118
  }
121
119
  return currentValue;
122
120
  };
123
- this.parseValue = (currentValueComponents, i, value, unit, endSymbol, parentFunctionName, bypassParsing = false, bypassVariableNames = [])=>{
121
+ this.parseValues = (currentValueComponents, i, value, unit, endSymbol, parentFunctionName, bypassParsing = false, bypassVariableNames = [])=>{
124
122
  const root = parentFunctionName === undefined;
125
123
  const isVarFunction = !root && (parentFunctionName.endsWith('$') || parentFunctionName.endsWith('var'));
126
124
  const checkIsString = (value)=>value === '\'' || value === '"';
@@ -145,7 +143,8 @@ class Rule {
145
143
  const valueComponent = {
146
144
  type: 'variable',
147
145
  name,
148
- variable: this.css.variables[name]
146
+ variable: this.css.variables[name],
147
+ token: currentValue
149
148
  };
150
149
  if (alpha) valueComponent.alpha = alpha;
151
150
  currentValueComponents.push(valueComponent);
@@ -153,7 +152,7 @@ class Rule {
153
152
  }
154
153
  };
155
154
  handleVariable(currentValue);
156
- if (!handled && this.colored) {
155
+ if (!handled) {
157
156
  const [colorName, alpha] = currentValue.split('/');
158
157
  handleVariable(colorName, alpha);
159
158
  }
@@ -168,10 +167,14 @@ class Rule {
168
167
  if (bypassParsing) {
169
168
  currentValueComponents.push({
170
169
  type: 'string',
171
- value: currentValue
170
+ value: currentValue,
171
+ token: currentValue
172
172
  });
173
173
  } else {
174
- currentValueComponents.push(this.parseValueComponent(currentValue, unit));
174
+ currentValueComponents.push({
175
+ ...this.parseValue(currentValue, unit),
176
+ token: currentValue
177
+ });
175
178
  }
176
179
  }
177
180
  currentValue = '';
@@ -196,27 +199,25 @@ class Rule {
196
199
  parse();
197
200
  }
198
201
  return i;
199
- } else if (!isString && val in START_SYMBOLS) {
202
+ } else if (!isString && val in VALUE_DELIMITERS) {
200
203
  const functionName = currentValue;
201
204
  const newValueComponent = {
202
205
  type: 'function',
203
206
  name: functionName,
204
207
  symbol: val,
205
- children: []
208
+ children: [],
209
+ token: ''
206
210
  };
207
211
  currentValueComponents.push(newValueComponent);
208
212
  currentValue = '';
209
213
  const functionDefinition = val === '(' ? this.css.config.functions?.[functionName] : undefined;
210
- if (!this.colored && functionDefinition?.colored) {
211
- // @ts-ignore
212
- this.colored = true;
213
- }
214
- i = this.parseValue(newValueComponent.children, ++i, value, functionDefinition?.unit ?? unit, START_SYMBOLS[val], functionName || parentFunctionName || '', bypassParsing || functionName === 'calc');
214
+ i = this.parseValues(newValueComponent.children, ++i, value, functionDefinition?.unit ?? unit, VALUE_DELIMITERS[val], functionName || parentFunctionName || '', bypassParsing || functionName === 'calc');
215
215
  } else if ((val === '|' || val === ' ') && endSymbol !== '}' && (!isString || parentFunctionName === 'path')) {
216
216
  parse();
217
217
  currentValueComponents.push({
218
218
  type: 'separator',
219
- value: ' '
219
+ value: ' ',
220
+ token: val
220
221
  });
221
222
  } else {
222
223
  if (!isString) {
@@ -231,7 +232,8 @@ class Rule {
231
232
  currentValueComponents.push({
232
233
  type: 'separator',
233
234
  value: val,
234
- text: (val === ',' ? '' : ' ') + val + (val === ',' ? '' : ' ')
235
+ text: (val === ',' ? '' : ' ') + val + (val === ',' ? '' : ' '),
236
+ token: val
235
237
  });
236
238
  continue;
237
239
  } else if (root && (val === '#' && (currentValue || currentValueComponents.length && currentValueComponents[currentValueComponents.length - 1]['type'] !== 'separator') || [
@@ -256,9 +258,8 @@ class Rule {
256
258
  };
257
259
  Object.assign(this, RegisteredRule);
258
260
  const { id, definition } = RegisteredRule;
259
- const { analyze, transformValue, declare, transformValueComponents, create, layer, unit, colored } = definition;
261
+ const { analyze, transformValue, declare, transformValueComponents, create, layer, unit } = definition;
260
262
  this.layer = layer;
261
- this.colored = !!colored;
262
263
  if (!definition.unit) definition.unit = '';
263
264
  if (!definition.separators) definition.separators = [
264
265
  ','
@@ -271,7 +272,7 @@ class Rule {
271
272
  this.declarations = definition.declarations;
272
273
  let stateToken;
273
274
  let prefixToken;
274
- if (layer === Layer.Semantic) {
275
+ if (layer === Layer.Utility) {
275
276
  // TODO: id 使用其他方式傳遞
276
277
  stateToken = className.slice(id.length - 1);
277
278
  } else {
@@ -280,11 +281,13 @@ class Rule {
280
281
  [valueToken, prefixToken] = analyze.call(this, className);
281
282
  } else {
282
283
  const indexOfColon = className.indexOf(':');
283
- this.prefix = className.slice(0, indexOfColon + 1);
284
+ this.keyToken = className.slice(0, indexOfColon + 1);
284
285
  valueToken = className.slice(indexOfColon + 1);
285
286
  }
286
287
  this.valueComponents = [];
287
- stateToken = valueToken.slice(this.parseValue(this.valueComponents, 0, valueToken, unit, '', undefined, false, id === 'animation' || id === 'animation-name' ? Object.keys(this.css.animations) : []));
288
+ const parsedValueIndex = this.parseValues(this.valueComponents, 0, valueToken, unit, '', undefined, false, definition.includeAnimations ? Object.keys(this.css.animations) : []);
289
+ this.valueToken = valueToken.slice(0, parsedValueIndex);
290
+ stateToken = valueToken.slice(parsedValueIndex);
288
291
  }
289
292
  // 2. !important
290
293
  if (stateToken[0] === '!') {
@@ -449,8 +452,8 @@ class Rule {
449
452
  // 5. atTokens
450
453
  for(let i = 1; i < stateTokens.length; i++){
451
454
  const atToken = stateTokens[i];
455
+ this.atToken = (this.atToken || '') + '@' + atToken;
452
456
  if (atToken) {
453
- this.atToken += '@' + atToken;
454
457
  if (atToken === 'rtl' || atToken === 'ltr') {
455
458
  this.direction = atToken;
456
459
  } else {
@@ -468,14 +471,7 @@ class Rule {
468
471
  });
469
472
  } else {
470
473
  const analyzeToken = (atComponentToken)=>{
471
- if (atComponentToken === 'all' || atComponentToken === 'print' || atComponentToken === 'screen' || atComponentToken === 'speech') {
472
- queryType = 'media';
473
- atComponents.push({
474
- type: 'media-type',
475
- token: atComponentToken,
476
- value: atComponentToken
477
- });
478
- } else if (atComponentToken === '&') {
474
+ if (atComponentToken === '&') {
479
475
  atComponents.push({
480
476
  type: 'operator',
481
477
  token: atComponentToken,
@@ -527,7 +523,7 @@ class Rule {
527
523
  unit: 'px'
528
524
  });
529
525
  } else {
530
- const valueComponent = this.parseValueComponent(token, 'px');
526
+ const valueComponent = this.parseValue(token, 'px');
531
527
  if (valueComponent.type === 'number') {
532
528
  atComponents.push({
533
529
  type: 'feature',
@@ -605,14 +601,14 @@ class Rule {
605
601
  }
606
602
  propertiesText.push(propertyText + ((this.important || important) && !propertyText.endsWith('!important') ? '!important' : ''));
607
603
  };
608
- const prefix = propertyName + ':';
604
+ const keyToken = propertyName + ':';
609
605
  const declarations = this.declarations[propertyName];
610
606
  if (Array.isArray(declarations)) {
611
607
  for (const value of declarations){
612
- push(prefix + String(value));
608
+ push(keyToken + String(value));
613
609
  }
614
610
  } else {
615
- push(prefix + String(declarations));
611
+ push(keyToken + String(declarations));
616
612
  }
617
613
  }
618
614
  // 創建 Natives
@@ -651,8 +647,6 @@ class Rule {
651
647
  switch(atComponent.type){
652
648
  case 'arbitrary':
653
649
  return atComponent.value;
654
- case 'media-type':
655
- return atComponent.value;
656
650
  case 'feature':
657
651
  return '(' + atComponent.name + ':' + atComponent.value + (atComponent.unit || '') + ')';
658
652
  case 'operator':
@@ -663,8 +657,8 @@ class Rule {
663
657
  get text() {
664
658
  return this.natives.map((eachNative)=>eachNative.text).join('');
665
659
  }
666
- parseValue;
667
- parseValueComponent(token, unit = this.definition.unit) {
660
+ parseValues;
661
+ parseValue(token, unit = this.definition.unit) {
668
662
  const defaultUnit = unit ?? this.definition.unit;
669
663
  let newUnit = '';
670
664
  let value;
@@ -695,7 +689,7 @@ class Rule {
695
689
  type: 'number'
696
690
  };
697
691
  }
698
- const matches = token.match(/^([+-.]?\d+(\.?\d+)?)(%|cm|mm|q|in|pt|pc|px|em|rem|ex|rex|cap|rcap|ch|rch|ic|ric|lh|rlh|vw|svw|lvw|dvw|vh|svh|lvh|dvh|vi|svi|lvi|dvi|vb|svb|lvb|dvb|vmin|svmin|lvmin|dvmin|vmax|svmax|lvmax|dvmax|cqw|cqh|cqi|cqb|cqmin|cqmax|deg|grad|rad|turn|s|ms|hz|khz|dpi|dpcm|dppx|x|fr|db|st)?$/);
692
+ const matches = token.match(UNIT_REGEX);
699
693
  // ['0.5deg', '0.5', 'deg', index: 0, input: '0.5deg', groups: undefined]
700
694
  if (matches) {
701
695
  value = +matches[1];
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ var core = require('../core.cjs');
4
+
5
+ function generateCSS(classes, css = new core.default()) {
6
+ let text = '';
7
+ css.add(...classes);
8
+ text = css.text;
9
+ css.delete(...classes);
10
+ return text;
11
+ }
12
+
13
+ module.exports = generateCSS;
@@ -0,0 +1,2 @@
1
+ import MasterCSS from '../core';
2
+ export default function generateCSS(classes: string[], css?: MasterCSS): string;
@@ -0,0 +1,11 @@
1
+ import MasterCSS from '../core.mjs';
2
+
3
+ function generateCSS(classes, css = new MasterCSS()) {
4
+ let text = '';
5
+ css.add(...classes);
6
+ text = css.text;
7
+ css.delete(...classes);
8
+ return text;
9
+ }
10
+
11
+ export { generateCSS as default };
@@ -27,4 +27,4 @@ function hexToRgb(hex) {
27
27
  ];
28
28
  }
29
29
 
30
- exports.hexToRgb = hexToRgb;
30
+ module.exports = hexToRgb;
@@ -1 +1 @@
1
- export declare function hexToRgb(hex: string): (number | undefined)[];
1
+ export default function hexToRgb(hex: string): (number | undefined)[];
@@ -25,4 +25,4 @@ function hexToRgb(hex) {
25
25
  ];
26
26
  }
27
27
 
28
- export { hexToRgb };
28
+ export { hexToRgb as default };
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ var rules = require('../config/rules.cjs');
4
+
5
+ function isCoreRule(id) {
6
+ return Object.hasOwnProperty.call(rules.default, id);
7
+ }
8
+
9
+ module.exports = isCoreRule;
@@ -0,0 +1 @@
1
+ export default function isCoreRule(id: string): boolean;
@@ -0,0 +1,7 @@
1
+ import rules from '../config/rules.mjs';
2
+
3
+ function isCoreRule(id) {
4
+ return Object.hasOwnProperty.call(rules, id);
5
+ }
6
+
7
+ export { isCoreRule as default };
@@ -8,23 +8,17 @@ var core = require('../core.cjs');
8
8
  * @param classes
9
9
  * @param options
10
10
  * @returns consistent classes
11
- */ function reorderForReadableClasses(classes, options) {
12
- let css;
13
- if (options?.css) {
14
- css = options?.css;
15
- } else {
16
- css = new core.default(options?.config);
17
- }
11
+ */ function reorderForReadableClasses(classes, css = new core.default()) {
18
12
  for (const eachClass of classes){
19
13
  css.add(eachClass);
20
14
  }
21
15
  return css.rules// 只保留樣式語法相關的 rules, 排除 keyframes 與 variables 在外
22
16
  .filter((eachRule)=>eachRule.layer).sort((a, b)=>{
23
- if (a.layer === layer.Layer.Semantic && b.layer !== layer.Layer.Semantic) {
24
- // 如果 a 是 Layer.Semantic 而 b 不是,则 a 应该排在 b 前面
17
+ if (a.layer === layer.Utility && b.layer !== layer.Utility) {
18
+ // 如果 a 是 Layer.Utility 而 b 不是,则 a 应该排在 b 前面
25
19
  return -1;
26
- } else if (a.layer !== layer.Layer.Semantic && b.layer === layer.Layer.Semantic) {
27
- // 如果 b 是 Layer.Semantic 而 a 不是,则 b 应该排在 a 前面
20
+ } else if (a.layer !== layer.Utility && b.layer === layer.Utility) {
21
+ // 如果 b 是 Layer.Utility 而 a 不是,则 b 应该排在 a 前面
28
22
  return 1;
29
23
  } else if (a.id !== b.id) {
30
24
  return a.className.localeCompare(b.className);
@@ -1,4 +1,3 @@
1
- import type { Config } from '../config';
2
1
  import MasterCSS from '../core';
3
2
  /**
4
3
  * Sorts classes in a consistent order
@@ -6,7 +5,4 @@ import MasterCSS from '../core';
6
5
  * @param options
7
6
  * @returns consistent classes
8
7
  */
9
- export default function reorderForReadableClasses(classes: string[], options?: {
10
- css?: MasterCSS;
11
- config?: Config;
12
- }): string[];
8
+ export default function reorderForReadableClasses(classes: string[], css?: MasterCSS): string[];
@@ -1,4 +1,4 @@
1
- import { Layer } from '../layer.mjs';
1
+ import Layer from '../layer.mjs';
2
2
  import MasterCSS from '../core.mjs';
3
3
 
4
4
  /**
@@ -6,23 +6,17 @@ import MasterCSS from '../core.mjs';
6
6
  * @param classes
7
7
  * @param options
8
8
  * @returns consistent classes
9
- */ function reorderForReadableClasses(classes, options) {
10
- let css;
11
- if (options?.css) {
12
- css = options?.css;
13
- } else {
14
- css = new MasterCSS(options?.config);
15
- }
9
+ */ function reorderForReadableClasses(classes, css = new MasterCSS()) {
16
10
  for (const eachClass of classes){
17
11
  css.add(eachClass);
18
12
  }
19
13
  return css.rules// 只保留樣式語法相關的 rules, 排除 keyframes 與 variables 在外
20
14
  .filter((eachRule)=>eachRule.layer).sort((a, b)=>{
21
- if (a.layer === Layer.Semantic && b.layer !== Layer.Semantic) {
22
- // 如果 a 是 Layer.Semantic 而 b 不是,则 a 应该排在 b 前面
15
+ if (a.layer === Layer.Utility && b.layer !== Layer.Utility) {
16
+ // 如果 a 是 Layer.Utility 而 b 不是,则 a 应该排在 b 前面
23
17
  return -1;
24
- } else if (a.layer !== Layer.Semantic && b.layer === Layer.Semantic) {
25
- // 如果 b 是 Layer.Semantic 而 a 不是,则 b 应该排在 a 前面
18
+ } else if (a.layer !== Layer.Utility && b.layer === Layer.Utility) {
19
+ // 如果 b 是 Layer.Utility 而 a 不是,则 b 应该排在 a 前面
26
20
  return 1;
27
21
  } else if (a.id !== b.id) {
28
22
  return a.className.localeCompare(b.className);
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@master/css","type":"module","scripts":{"build":"techor build \"src/**/*.ts\"","dev":"pnpm build --watch","test":"jest","type-check":"tsc --noEmit","lint":"eslint src"},"license":"MIT","description":"The CSS language and framework for rapidly building modern and high-performance websites","author":"Aoyue Design LLC.","funding":"https://css.master.co/docs/donate","homepage":"https://css.master.co","bugs":{"url":"https://github.com/master-co/css/issues"},"repository":{"type":"git","url":"https://github.com/master-co/css.git","directory":"packages/css"},"keywords":["style","styles","html","variants","virtual","virtual-css","utility","css","ui","lightweight","class","webpack","plugin","integration","vite","parcel","build-tools","mastercss"],"sideEffects":false,"main":"./dist/index.cjs","jsnext:main":"./dist/index.mjs","esnext":"./dist/index.mjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.cjs","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"bin":"./dist/bin/index.mjs","files":["dist"],"publishConfig":{"access":"public","provenance":true},"dependencies":{"@master/colors":"^2.0.0","@master/normal.css":"^2.1.0","@techor/extend":"^3.0.18"},"devDependencies":{"css-shared":"^2.0.0-rc.26","csstype":"^3.1.3"},"version":"2.0.0-rc.26"}
1
+ {"name":"@master/css","type":"module","scripts":{"build":"techor build \"src/**/*.ts\"","dev":"pnpm build --watch","test":"jest","type-check":"tsc --noEmit","lint":"eslint src"},"license":"MIT","description":"The CSS language and framework for rapidly building modern and high-performance websites","author":"Aoyue Design LLC.","funding":"https://css.master.co/docs/donate","homepage":"https://css.master.co","bugs":{"url":"https://github.com/master-co/css/issues"},"repository":{"type":"git","url":"https://github.com/master-co/css.git","directory":"packages/css"},"keywords":["style","styles","html","variants","virtual","virtual-css","utility","css","ui","lightweight","class","webpack","plugin","integration","vite","parcel","build-tools","mastercss"],"sideEffects":false,"main":"./dist/index.cjs","jsnext:main":"./dist/index.mjs","esnext":"./dist/index.mjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"require":"./dist/index.cjs","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"bin":"./dist/bin/index.mjs","files":["dist"],"publishConfig":{"access":"public","provenance":true},"dependencies":{"@master/colors":"^2.0.0","@master/normal.css":"^2.1.0","@techor/extend":"^3.0.18"},"devDependencies":{"@master/css-shared":"^2.0.0-rc.27","csstype":"^3.1.3"},"version":"2.0.0-rc.27"}
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- const BASE_UNIT_REGEX = /^([+-]?(?:\d+(?:\.?\d+)?|\.\d+))x$/m;
4
-
5
- exports.BASE_UNIT_REGEX = BASE_UNIT_REGEX;
@@ -1 +0,0 @@
1
- export declare const BASE_UNIT_REGEX: RegExp;
@@ -1,3 +0,0 @@
1
- const BASE_UNIT_REGEX = /^([+-]?(?:\d+(?:\.?\d+)?|\.\d+))x$/m;
2
-
3
- export { BASE_UNIT_REGEX };
@@ -1,10 +0,0 @@
1
- 'use strict';
2
-
3
- const START_SYMBOLS = {
4
- '(': ')',
5
- '\'': '\'',
6
- '"': '"',
7
- '{': '}'
8
- };
9
-
10
- exports.START_SYMBOLS = START_SYMBOLS;
@@ -1,6 +0,0 @@
1
- export declare const START_SYMBOLS: {
2
- '(': string;
3
- '\'': string;
4
- '"': string;
5
- '{': string;
6
- };
@@ -1,8 +0,0 @@
1
- const START_SYMBOLS = {
2
- '(': ')',
3
- '\'': '\'',
4
- '"': '"',
5
- '{': '}'
6
- };
7
-
8
- export { START_SYMBOLS };
@@ -1,12 +0,0 @@
1
- 'use strict';
2
-
3
- function concatArrays(originVal, newVal) {
4
- if (Array.isArray(originVal) && Array.isArray(newVal)) {
5
- // concat logic
6
- return originVal.concat(newVal);
7
- }
8
- return newVal // always return newVal as fallback!!
9
- ;
10
- }
11
-
12
- exports.concatArrays = concatArrays;
@@ -1 +0,0 @@
1
- export declare function concatArrays(originVal: any, newVal: any): any | any[];