@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
@@ -15,7 +15,6 @@ const selectors = {
15
15
  '::-webkit-slider-runnable-track',
16
16
  '::-moz-range-track'
17
17
  ],
18
- '::meter': '::-webkit-meter',
19
18
  '::resizer': '::-webkit-resizer',
20
19
  '::progress': '::-webkit-progress',
21
20
  ':first': ':first-child',
@@ -7,7 +7,6 @@ declare const selectors: {
7
7
  '::scrollbar-corner': string;
8
8
  '::slider-thumb': string[];
9
9
  '::slider-runnable-track': string[];
10
- '::meter': string;
11
10
  '::resizer': string;
12
11
  '::progress': string;
13
12
  ':first': string;
@@ -13,7 +13,6 @@ const selectors = {
13
13
  '::-webkit-slider-runnable-track',
14
14
  '::-moz-range-track'
15
15
  ],
16
- '::meter': '::-webkit-meter',
17
16
  '::resizer': '::-webkit-resizer',
18
17
  '::progress': '::-webkit-progress',
19
18
  ':first': ':first-child',
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const semantics = {
3
+ const utilities = {
4
4
  square: {
5
5
  'aspect-ratio': '1/1'
6
6
  },
@@ -16,9 +16,6 @@ const semantics = {
16
16
  hidden: {
17
17
  display: 'none'
18
18
  },
19
- hide: {
20
- display: 'none'
21
- },
22
19
  block: {
23
20
  display: 'block'
24
21
  },
@@ -191,4 +188,4 @@ const semantics = {
191
188
  }
192
189
  };
193
190
 
194
- module.exports = semantics;
191
+ module.exports = utilities;
@@ -1,4 +1,4 @@
1
- declare const semantics: {
1
+ declare const utilities: {
2
2
  readonly square: {
3
3
  readonly 'aspect-ratio': "1/1";
4
4
  };
@@ -14,9 +14,6 @@ declare const semantics: {
14
14
  readonly hidden: {
15
15
  readonly display: "none";
16
16
  };
17
- readonly hide: {
18
- readonly display: "none";
19
- };
20
17
  readonly block: {
21
18
  readonly display: "block";
22
19
  };
@@ -188,4 +185,4 @@ declare const semantics: {
188
185
  readonly height: "fit-content";
189
186
  };
190
187
  };
191
- export default semantics;
188
+ export default utilities;
@@ -1,4 +1,4 @@
1
- const semantics = {
1
+ const utilities = {
2
2
  square: {
3
3
  'aspect-ratio': '1/1'
4
4
  },
@@ -14,9 +14,6 @@ const semantics = {
14
14
  hidden: {
15
15
  display: 'none'
16
16
  },
17
- hide: {
18
- display: 'none'
19
- },
20
17
  block: {
21
18
  display: 'block'
22
19
  },
@@ -189,4 +186,4 @@ const semantics = {
189
186
  }
190
187
  };
191
188
 
192
- export { semantics as default };
189
+ export { utilities as default };
package/dist/core.cjs CHANGED
@@ -7,7 +7,7 @@ var index = require('./config/index.cjs');
7
7
  var layer = require('./layer.cjs');
8
8
  var hexToRgb = require('./utils/hex-to-rgb.cjs');
9
9
  var flattenObject = require('./utils/flatten-object.cjs');
10
- var extendConfig = require('./functions/extend-config.cjs');
10
+ var extendConfig = require('./utils/extend-config.cjs');
11
11
 
12
12
  class MasterCSS {
13
13
  customConfig;
@@ -16,15 +16,13 @@ class MasterCSS {
16
16
  ruleBy;
17
17
  classesUsage;
18
18
  config;
19
- RegisteredSemanticRules;
20
- RegisteredRules;
19
+ Rules;
21
20
  constructor(customConfig = index.config){
22
21
  this.customConfig = customConfig;
23
22
  this.rules = [];
24
23
  this.ruleBy = {};
25
24
  this.classesUsage = {};
26
- this.RegisteredSemanticRules = [];
27
- this.RegisteredRules = [];
25
+ this.Rules = [];
28
26
  if (!customConfig?.override) {
29
27
  this.config = extendConfig(index.config, customConfig);
30
28
  } else {
@@ -42,8 +40,7 @@ class MasterCSS {
42
40
  this.variables = {};
43
41
  this.queries = {};
44
42
  this.animations = {};
45
- this.RegisteredRules.length = 0;
46
- this.RegisteredSemanticRules.length = 0;
43
+ this.Rules.length = 0;
47
44
  this.variablesNativeRules = {};
48
45
  this.hasKeyframesRule = false;
49
46
  const colorVariableNames = {
@@ -51,7 +48,7 @@ class MasterCSS {
51
48
  currentColor: undefined,
52
49
  transparent: undefined
53
50
  };
54
- const { styles, selectors, variables, semantics, queries, rules, animations } = this.config;
51
+ const { styles, selectors, variables, utilities, queries, rules, animations } = this.config;
55
52
  function escapeString(str) {
56
53
  return str.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
57
54
  }
@@ -82,89 +79,104 @@ class MasterCSS {
82
79
  }
83
80
  if (variables) {
84
81
  const unexecutedAliasVariable = {};
85
- const parseVariable = (variable, name, mode)=>{
86
- if (!variable) return;
87
- const addVariable = (name, variableValue, replacedMode, alpha)=>{
88
- if (variableValue === undefined) return;
89
- if (variableValue.type === 'color') {
82
+ const resolveVariable = (variableDefinition, name, mode)=>{
83
+ if (!variableDefinition === undefined || variableDefinition === null) return;
84
+ const addVariable = (name, variable, replacedMode, alpha)=>{
85
+ if (variable === undefined) return;
86
+ const flatName = name.join('-');
87
+ const groups = name.slice(0, -1).filter(Boolean);
88
+ const key = (name[0] === '' ? '-' : '') + name[name.length - 1];
89
+ variable.key = key;
90
+ variable.name = flatName;
91
+ if (groups.length) variable.group = groups.join('.');
92
+ if (variable.type === 'color') {
90
93
  if (alpha) {
91
- const slashIndex = variableValue.value.indexOf('/');
92
- variableValue = {
93
- ...variableValue,
94
- value: slashIndex === -1 ? variableValue.value + ' / ' + (alpha.startsWith('0.') ? alpha.slice(1) : alpha) : variableValue.value.slice(0, slashIndex + 2) + String(+variableValue.value.slice(slashIndex + 2) * +alpha).slice(1)
94
+ const slashIndex = variable.value.indexOf('/');
95
+ variable = {
96
+ ...variable,
97
+ value: slashIndex === -1 ? variable.value + ' / ' + (alpha.startsWith('0.') ? alpha.slice(1) : alpha) : variable.value.slice(0, slashIndex + 2) + String(+variable.value.slice(slashIndex + 2) * +alpha).slice(1)
95
98
  };
96
99
  }
97
- colorVariableNames[name] = undefined;
100
+ colorVariableNames[flatName] = undefined;
98
101
  }
99
102
  const currentMode = replacedMode ?? mode;
100
103
  if (currentMode !== undefined) {
101
- if (Object.prototype.hasOwnProperty.call(this.variables, name)) {
102
- const variable = this.variables[name];
104
+ if (Object.prototype.hasOwnProperty.call(this.variables, flatName)) {
105
+ const foundVariable = this.variables[flatName];
103
106
  if (currentMode) {
104
- if (!variable.modes) {
105
- variable.modes = {};
107
+ if (!foundVariable.modes) {
108
+ foundVariable.modes = {};
106
109
  }
107
- variable.modes[currentMode] = variableValue;
110
+ foundVariable.modes[currentMode] = variable;
108
111
  } else {
109
- variable.value = variableValue.value;
110
- if (variableValue.type === 'color') {
111
- variable.space = variableValue.space;
112
+ foundVariable.value = variable.value;
113
+ if (variable.type === 'color') {
114
+ foundVariable.space = variable.space;
112
115
  }
113
116
  }
114
117
  } else {
115
118
  if (currentMode) {
116
119
  const newVariable = {
117
- type: variableValue.type,
120
+ key: variable.key,
121
+ name: variable.name,
122
+ group: variable.group,
123
+ type: variable.type,
118
124
  modes: {
119
- [currentMode]: variableValue
125
+ [currentMode]: variable
120
126
  }
121
127
  };
122
- if (variableValue.type === 'color') {
123
- newVariable.space = variableValue.space;
128
+ if (variable.type === 'color') {
129
+ newVariable.space = variable.space;
124
130
  }
125
- this.variables[name] = newVariable;
131
+ this.variables[flatName] = newVariable;
126
132
  } else {
127
- this.variables[name] = variableValue;
133
+ this.variables[flatName] = variable;
128
134
  }
129
135
  }
130
136
  } else {
131
- this.variables[name] = variableValue;
137
+ this.variables[flatName] = variable;
132
138
  }
133
139
  };
134
- const type = typeof variable;
135
- if (type === 'object') {
136
- if (Array.isArray(variable)) {
140
+ if (typeof variableDefinition === 'object') {
141
+ if (Array.isArray(variableDefinition)) {
137
142
  addVariable(name, {
138
143
  type: 'string',
139
- value: variable.join(',')
144
+ value: variableDefinition.join(',')
140
145
  });
141
146
  } else {
142
- const keys = Object.keys(variable);
147
+ const keys = Object.keys(variableDefinition);
143
148
  for (const eachKey of keys){
144
149
  if (eachKey === '' || eachKey.startsWith('@')) {
145
- parseVariable(variable[eachKey], name, eachKey || keys.some((eachKey)=>eachKey.startsWith('@')) ? eachKey.slice(1) : undefined);
150
+ resolveVariable(variableDefinition[eachKey], name, eachKey || keys.some((eachKey)=>eachKey.startsWith('@')) ? eachKey.slice(1) : undefined);
146
151
  } else {
147
- parseVariable(variable[eachKey], name + '-' + eachKey, undefined);
152
+ resolveVariable(variableDefinition[eachKey], [
153
+ ...name,
154
+ eachKey
155
+ ]);
148
156
  }
149
157
  }
150
158
  }
151
- } else if (type === 'number') {
159
+ } else if (typeof variableDefinition === 'number') {
152
160
  addVariable(name, {
153
161
  type: 'number',
154
- value: variable
162
+ value: variableDefinition
155
163
  });
156
- addVariable('-' + name, {
164
+ addVariable([
165
+ '',
166
+ ...name
167
+ ], {
157
168
  type: 'number',
158
- value: variable * -1
169
+ value: variableDefinition * -1
159
170
  });
160
- } else if (type === 'string') {
161
- const aliasResult = /^\$\((.*?)\)(?: ?\/ ?(.+?))?$/.exec(variable);
171
+ } else if (typeof variableDefinition === 'string') {
172
+ const aliasResult = /^\$\((.*?)\)(?: ?\/ ?(.+?))?$/.exec(variableDefinition);
173
+ const flatName = name.join('-');
162
174
  if (aliasResult) {
163
- if (!Object.prototype.hasOwnProperty.call(unexecutedAliasVariable, name)) {
164
- unexecutedAliasVariable[name] = {};
175
+ if (!Object.prototype.hasOwnProperty.call(unexecutedAliasVariable, flatName)) {
176
+ unexecutedAliasVariable[flatName] = {};
165
177
  }
166
- unexecutedAliasVariable[name][mode] = ()=>{
167
- delete unexecutedAliasVariable[name][mode];
178
+ unexecutedAliasVariable[flatName][mode] = ()=>{
179
+ delete unexecutedAliasVariable[flatName][mode];
168
180
  const [alias, aliasMode] = aliasResult[1].split('@');
169
181
  if (alias) {
170
182
  if (Object.prototype.hasOwnProperty.call(unexecutedAliasVariable, alias)) {
@@ -200,16 +212,16 @@ class MasterCSS {
200
212
  }
201
213
  };
202
214
  } else {
203
- const hexColorResult = /^#([A-Fa-f0-9]{3,4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.exec(variable);
215
+ const hexColorResult = /^#([A-Fa-f0-9]{3,4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.exec(variableDefinition);
204
216
  if (hexColorResult) {
205
- const [r, g, b, a] = hexToRgb.hexToRgb(hexColorResult[1]);
217
+ const [r, g, b, a] = hexToRgb(hexColorResult[1]);
206
218
  addVariable(name, {
207
219
  type: 'color',
208
220
  value: `${r} ${g} ${b}${a === 1 ? '' : ' / ' + a}`,
209
221
  space: 'rgb'
210
222
  });
211
223
  } else {
212
- const rgbFunctionResult = /^rgb\( *([0-9]{1,3})(?: *, *| +)([0-9]{1,3})(?: *, *| +)([0-9]{1,3}) *(?:(?:,|\/) *(.*?) *)?\)$/.exec(variable);
224
+ const rgbFunctionResult = /^rgb\( *([0-9]{1,3})(?: *, *| +)([0-9]{1,3})(?: *, *| +)([0-9]{1,3}) *(?:(?:,|\/) *(.*?) *)?\)$/.exec(variableDefinition);
213
225
  if (rgbFunctionResult) {
214
226
  addVariable(name, {
215
227
  type: 'color',
@@ -217,7 +229,7 @@ class MasterCSS {
217
229
  space: 'rgb'
218
230
  });
219
231
  } else {
220
- const hslFunctionResult = /^hsl\((.*?)\)$/.exec(variable);
232
+ const hslFunctionResult = /^hsl\((.*?)\)$/.exec(variableDefinition);
221
233
  if (hslFunctionResult) {
222
234
  addVariable(name, {
223
235
  type: 'color',
@@ -227,7 +239,7 @@ class MasterCSS {
227
239
  } else {
228
240
  addVariable(name, {
229
241
  type: 'string',
230
- value: variable
242
+ value: variableDefinition
231
243
  });
232
244
  }
233
245
  }
@@ -236,8 +248,11 @@ class MasterCSS {
236
248
  }
237
249
  };
238
250
  for(const parnetKey in variables){
239
- parseVariable(variables[parnetKey], parnetKey);
251
+ resolveVariable(variables[parnetKey], [
252
+ parnetKey
253
+ ]);
240
254
  }
255
+ // todo: address to the target variable
241
256
  for (const name of Object.keys(unexecutedAliasVariable)){
242
257
  for (const mode of Object.keys(unexecutedAliasVariable[name])){
243
258
  unexecutedAliasVariable[name][mode]?.();
@@ -261,31 +276,31 @@ class MasterCSS {
261
276
  }
262
277
  }
263
278
  const flattedStyles = styles ? flattenObject.flattenObject(styles) : {};
264
- const semanticNames = Object.keys(flattedStyles);
265
- const handleSemanticName = (semanticName)=>{
266
- if (Object.prototype.hasOwnProperty.call(this.styles, semanticName)) return;
267
- const currentClass = this.styles[semanticName] = [];
268
- const className = flattedStyles[semanticName];
279
+ const utilityNames = Object.keys(flattedStyles);
280
+ const handleUtilityName = (utilityName)=>{
281
+ if (Object.prototype.hasOwnProperty.call(this.styles, utilityName)) return;
282
+ const currentClass = this.styles[utilityName] = [];
283
+ const className = flattedStyles[utilityName];
269
284
  if (!className) return;
270
285
  const classNames = className.replace(/(?:\n(?:\s*))+/g, ' ').trim().split(' ');
271
286
  for (const eachClassName of classNames){
272
287
  const handle = (className)=>{
273
288
  if (Object.prototype.hasOwnProperty.call(this.stylesBy, className)) {
274
289
  const currentRelation = this.stylesBy[className];
275
- if (!currentRelation.includes(semanticName)) {
276
- currentRelation.push(semanticName);
290
+ if (!currentRelation.includes(utilityName)) {
291
+ currentRelation.push(utilityName);
277
292
  }
278
293
  } else {
279
294
  this.stylesBy[className] = [
280
- semanticName
295
+ utilityName
281
296
  ];
282
297
  }
283
298
  if (!currentClass.includes(className)) {
284
299
  currentClass.push(className);
285
300
  }
286
301
  };
287
- if (semanticNames.includes(eachClassName)) {
288
- handleSemanticName(eachClassName);
302
+ if (utilityNames.includes(eachClassName)) {
303
+ handleUtilityName(eachClassName);
289
304
  for (const parentClassName of this.styles[eachClassName]){
290
305
  handle(parentClassName);
291
306
  }
@@ -294,49 +309,54 @@ class MasterCSS {
294
309
  }
295
310
  }
296
311
  };
297
- for (const eachSemanticName of semanticNames){
298
- handleSemanticName(eachSemanticName);
312
+ for (const eachUtilityName of utilityNames){
313
+ handleUtilityName(eachUtilityName);
299
314
  }
300
- if (semantics) {
301
- Object.entries(semantics).sort((a, b)=>a[0].localeCompare(b[0])).forEach(([id, declarations], index)=>{
302
- this.RegisteredSemanticRules.push({
303
- id: '.' + id,
304
- match: new RegExp('^' + escapeString(id) + '(?=!|\\*|>|\\+|~|:|\\[|@|_|\\.|$)', 'm'),
305
- order: index,
306
- definition: {
307
- declarations,
308
- layer: layer.Layer.Semantic
309
- }
310
- });
311
- });
312
- }
313
- if (rules) {
314
- const rulesEntries = Object.entries(rules).sort((a, b)=>{
315
+ if (rules || utilities) {
316
+ const rulesEntries = [];
317
+ if (utilities) {
318
+ for(const utilityName in utilities){
319
+ const declarations = utilities[utilityName];
320
+ rulesEntries.push([
321
+ utilityName,
322
+ {
323
+ declarations,
324
+ layer: layer.Utility
325
+ }
326
+ ]);
327
+ }
328
+ }
329
+ if (rules) {
330
+ rulesEntries.push(...Object.entries(rules));
331
+ }
332
+ const rulesEntriesLength = rulesEntries.length;
333
+ const colorNames = Object.keys(colorVariableNames);
334
+ rulesEntries.sort((a, b)=>{
315
335
  if (a[1].layer !== b[1].layer) {
316
336
  return (b[1].layer || 0) - (a[1].layer || 0);
317
337
  }
318
338
  return b[0].localeCompare(a[0]);
319
- });
320
- const rulesEntriesLength = rulesEntries.length;
321
- const colorNames = Object.keys(colorVariableNames);
322
- rulesEntries.forEach(([id, eachRuleDefinition], index)=>{
323
- const eachRegisteredRule = {
339
+ }).forEach(([id, eachRuleDefinition], index)=>{
340
+ const EachRule = {
324
341
  id,
342
+ keys: [],
325
343
  variables: {},
326
- order: this.RegisteredSemanticRules.length + rulesEntriesLength - 1 - index,
344
+ matchers: {},
345
+ order: rulesEntriesLength - 1 - index,
327
346
  definition: eachRuleDefinition
328
347
  };
329
- this.RegisteredRules.push(eachRegisteredRule);
330
- const match = eachRuleDefinition.match;
348
+ this.Rules.push(EachRule);
349
+ const { matcher, layer: layer$1, subkey, ambiguousKeys, ambiguousValues, sign } = eachRuleDefinition;
350
+ if (layer$1 === layer.Utility) {
351
+ EachRule.id = '.' + id;
352
+ EachRule.matchers.arbitrary = new RegExp('^' + escapeString(id) + '(?=!|\\*|>|\\+|~|:|\\[|@|_|\\.|$)', 'm');
353
+ }
331
354
  // todo: 不可使用 startsWith 判斷,應改為更精準的從 config.variables 取得目標變數群組,但 config.variables 中的值還沒被 resolve 像是 Array
332
- const addResolvedVariables = (prefix)=>{
355
+ const addResolvedVariables = (groupName)=>{
333
356
  for(const eachVariableName in this.variables){
334
- if (eachVariableName.startsWith(prefix + '-') || eachVariableName.startsWith('-' + prefix + '-')) {
335
- const simplifiedName = eachVariableName.slice(prefix.length + (prefix.startsWith('-') ? 0 : 1));
336
- eachRegisteredRule.variables[simplifiedName] = {
337
- ...this.variables[eachVariableName],
338
- name: eachVariableName
339
- };
357
+ const eachVariable = this.variables[eachVariableName];
358
+ if (eachVariable.group === groupName) {
359
+ EachRule.variables[eachVariable.key] = eachVariable;
340
360
  }
341
361
  }
342
362
  };
@@ -348,26 +368,49 @@ class MasterCSS {
348
368
  }
349
369
  // 2. custom `config.variables`
350
370
  addResolvedVariables(id);
351
- if (match) {
352
- if (Array.isArray(match)) {
353
- const [key, values = []] = match;
354
- const valueMatches = [];
355
- if (values.length) {
356
- valueMatches.push(`(?:${values.join('|')})(?![a-zA-Z0-9-])`);
357
- }
358
- if (Object.keys(eachRegisteredRule.variables).length) {
359
- valueMatches.push(`(?:${Object.keys(eachRegisteredRule.variables).join('|')})(?![a-zA-Z0-9-])`);
371
+ const keys = [];
372
+ let { key } = eachRuleDefinition;
373
+ if (layer$1 === layer.NativeShorthand || layer$1 === layer.Native) {
374
+ if (!key) eachRuleDefinition.key = key = id;
375
+ keys.push(id);
376
+ }
377
+ if (sign) {
378
+ EachRule.matchers.arbitrary = new RegExp(`^${sign}[^!*>+~:[@_]+\\|`);
379
+ } else if (!matcher) {
380
+ const colorsPatten = colorNames.join('|');
381
+ if (!key && !subkey) {
382
+ keys.push(id);
383
+ } else {
384
+ if (key && !keys.includes(key)) keys.push(key);
385
+ if (subkey) keys.push(subkey);
386
+ if (layer$1 === layer.Shorthand) {
387
+ keys.push(id);
360
388
  }
361
- if (eachRuleDefinition.colored) {
362
- valueMatches.push('#', '(?:color|color-contrast|color-mix|hwb|lab|lch|oklab|oklch|rgb|rgba|hsl|hsla)\\(.*\\)', `(?:${colorNames.join('|')})(?![a-zA-Z0-9-])`);
389
+ }
390
+ if (ambiguousKeys?.length) {
391
+ const ambiguousKeyPattern = ambiguousKeys.length > 1 ? `(?:${ambiguousKeys.join('|')})` : ambiguousKeys[0];
392
+ const variableKeys = Object.keys(EachRule.variables);
393
+ if (ambiguousValues?.length) {
394
+ const ambiguousValuePatterns = [];
395
+ for (const eachAmbiguousValue of ambiguousValues){
396
+ if (eachAmbiguousValue instanceof RegExp) {
397
+ ambiguousValuePatterns.push(eachAmbiguousValue.source.replace('\\$colors', colorsPatten));
398
+ } else {
399
+ ambiguousValuePatterns.unshift(`${eachAmbiguousValue}(?:\\b|_)`);
400
+ }
401
+ }
402
+ EachRule.matchers.value = new RegExp(`^${ambiguousKeyPattern}:(?:${ambiguousValuePatterns.join('|')})[^|]*?(?:@|$)`);
363
403
  }
364
- if (eachRuleDefinition.numeric) {
365
- valueMatches.push('[\\d\\.]', '(?:max|min|calc|clamp)\\(.*\\)');
404
+ if (variableKeys.length) {
405
+ EachRule.matchers.variable = new RegExp(`^${ambiguousKeyPattern}:(?:${variableKeys.join('|')}(?![a-zA-Z0-9-]))[^|]*?(?:@|$)`);
366
406
  }
367
- if (valueMatches.length) eachRegisteredRule.match = new RegExp(`^${key}:(?:${valueMatches.join('|')})[^|]*?(?:@|$)`);
368
- } else {
369
- eachRegisteredRule.match = match;
370
407
  }
408
+ } else {
409
+ EachRule.matchers.arbitrary = matcher;
410
+ }
411
+ if (keys.length) {
412
+ EachRule.keys = keys;
413
+ EachRule.matchers.key = new RegExp(`^${keys.length > 1 ? `(${keys.join('|')})` : keys[0]}:`);
371
414
  }
372
415
  });
373
416
  }
@@ -377,17 +420,29 @@ class MasterCSS {
377
420
  * @param className
378
421
  * @returns css text
379
422
  */ match(className) {
380
- // 1. rules
381
- for (const eachRegisteredRule of this.RegisteredRules){
382
- if (eachRegisteredRule.match?.test(className) || (eachRegisteredRule.definition.layer === layer.Layer.Native || eachRegisteredRule.definition.layer === layer.Layer.NativeShorthand || eachRegisteredRule.definition.layer === layer.Layer.CoreNative || eachRegisteredRule.definition.layer === layer.Layer.CoreNativeShorthand) && className.startsWith(eachRegisteredRule.id + ':')) {
383
- return eachRegisteredRule;
384
- }
423
+ /**
424
+ * 1. variable
425
+ * @example fg:primary bg:blue
426
+ */ for (const EachRule of this.Rules){
427
+ if (EachRule.matchers.variable?.test(className)) return EachRule;
385
428
  }
386
- // 2. semantic rules
387
- for (const EachRegisteredSemanticRule of this.RegisteredSemanticRules){
388
- if (EachRegisteredSemanticRule.match?.test(className)) {
389
- return EachRegisteredSemanticRule;
390
- }
429
+ /**
430
+ * 2. value (ambiguous.key * ambiguous.values)
431
+ * @example bg:current box:content font:12
432
+ */ for (const EachRule of this.Rules){
433
+ if (EachRule.matchers.value?.test(className)) return EachRule;
434
+ }
435
+ /**
436
+ * 3. full key
437
+ * @example text-align:center color:blue-40
438
+ */ for (const EachRule of this.Rules){
439
+ if (EachRule.matchers.key?.test(className)) return EachRule;
440
+ }
441
+ /**
442
+ * 4. arbitrary
443
+ * @example custom RegExp, utility
444
+ */ for (const EachRule of this.Rules){
445
+ if (EachRule.matchers.arbitrary?.test(className)) return EachRule;
391
446
  }
392
447
  }
393
448
  /**
@@ -405,14 +460,19 @@ class MasterCSS {
405
460
  * @returns Rule
406
461
  */ create(syntax) {
407
462
  if (Object.prototype.hasOwnProperty.call(this.ruleBy, syntax)) return this.ruleBy[syntax];
408
- const RegistedRule = this.match(syntax);
409
- if (RegistedRule) {
410
- return new rule.Rule(syntax, RegistedRule, this);
463
+ const RegisteredRule = this.match(syntax);
464
+ if (RegisteredRule) {
465
+ return new rule.Rule(syntax, RegisteredRule, this);
411
466
  }
412
467
  }
413
468
  /**
414
469
  * 根據蒐集到的所有 DOM class 重新 create
415
- */ refresh(customConfig = this.customConfig) {
470
+ */ refresh(customConfig) {
471
+ if (customConfig) {
472
+ this.customConfig = customConfig;
473
+ } else {
474
+ customConfig = this.customConfig;
475
+ }
416
476
  if (!customConfig?.override) {
417
477
  // @ts-ignore
418
478
  this.config = extendConfig(index.config, customConfig);
@@ -530,7 +590,7 @@ class MasterCSS {
530
590
  if (!keyframe.usage) keyframe.usage = 0;
531
591
  if (!--keyframe.usage && keyframe.native) {
532
592
  const nativeIndex = keyframeRule.natives.indexOf(keyframe.native);
533
- this.style.sheet?.deleteRule(Object.keys(this.variablesNativeRules).length + nativeIndex);
593
+ sheet?.deleteRule(Object.keys(this.variablesNativeRules).length + nativeIndex);
534
594
  keyframeRule.natives.splice(nativeIndex, 1);
535
595
  keyframe.native = undefined;
536
596
  }
@@ -756,7 +816,6 @@ class MasterCSS {
756
816
  }
757
817
  this.rules.splice(index, 0, rule);
758
818
  this.ruleBy[className] = rule;
759
- // 只在瀏覽器端運行
760
819
  if (this.style) {
761
820
  const sheet = this.style.sheet;
762
821
  let cssRuleIndex = 0;
@@ -792,6 +851,7 @@ class MasterCSS {
792
851
  // animations
793
852
  this.handleRuleWithAnimationNames(rule);
794
853
  rule.definition.insert?.call(rule);
854
+ return index;
795
855
  }
796
856
  get text() {
797
857
  return this.rules.map((eachRule)=>eachRule.text).join('');
@@ -855,7 +915,7 @@ class MasterCSS {
855
915
  if (variable.usage) {
856
916
  variable.usage++;
857
917
  } else {
858
- const addProperty = (mode, variableValue)=>{
918
+ const addProperty = (mode, variable)=>{
859
919
  let nativeRule = this.variablesNativeRules[mode];
860
920
  if (!nativeRule) {
861
921
  let cssRule;
@@ -925,7 +985,7 @@ class MasterCSS {
925
985
  }
926
986
  const propertyName = '--' + eachVariableName;
927
987
  if (!initializing || !nativeRule.cssRule.style.getPropertyValue(propertyName)) {
928
- nativeRule.cssRule.style.setProperty(propertyName, String(variableValue.value));
988
+ nativeRule.cssRule.style.setProperty(propertyName, String(variable.value));
929
989
  }
930
990
  };
931
991
  if (variable.value) {