@master/css 2.0.0-rc.25 → 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 (93) 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 +7 -7
  7. package/dist/config/index.d.ts +12 -13
  8. package/dist/config/index.mjs +6 -6
  9. package/dist/config/queries.cjs +17 -0
  10. package/dist/config/queries.d.ts +22 -0
  11. package/dist/config/queries.mjs +15 -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/config/variables.mjs +2 -2
  22. package/dist/core.cjs +260 -195
  23. package/dist/core.d.ts +20 -16
  24. package/dist/core.mjs +258 -193
  25. package/dist/index.cjs +45 -15
  26. package/dist/index.d.ts +13 -3
  27. package/dist/index.mjs +15 -7
  28. package/dist/layer.cjs +25 -20
  29. package/dist/layer.d.ts +26 -9
  30. package/dist/layer.mjs +22 -19
  31. package/dist/rule.cjs +147 -125
  32. package/dist/rule.d.ts +58 -20
  33. package/dist/rule.mjs +147 -125
  34. package/dist/tokens/screen-sizes.cjs +2 -2
  35. package/dist/tokens/screen-sizes.mjs +2 -2
  36. package/dist/utils/are-rule-modes-equal.cjs +7 -0
  37. package/dist/utils/are-rule-modes-equal.d.ts +2 -0
  38. package/dist/utils/are-rule-modes-equal.mjs +5 -0
  39. package/dist/utils/are-rule-queries-equal.cjs +22 -0
  40. package/dist/utils/are-rule-queries-equal.d.ts +2 -0
  41. package/dist/utils/are-rule-queries-equal.mjs +20 -0
  42. package/dist/utils/are-rule-selectors-equal.cjs +29 -0
  43. package/dist/utils/are-rule-selectors-equal.d.ts +2 -0
  44. package/dist/utils/are-rule-selectors-equal.mjs +27 -0
  45. package/dist/utils/are-rule-states-equal.cjs +11 -0
  46. package/dist/utils/are-rule-states-equal.d.ts +2 -0
  47. package/dist/utils/are-rule-states-equal.mjs +9 -0
  48. package/dist/utils/are-rules-duplicated.cjs +17 -0
  49. package/dist/utils/are-rules-duplicated.d.ts +2 -0
  50. package/dist/utils/are-rules-duplicated.mjs +15 -0
  51. package/dist/utils/extend-config.cjs +27 -14
  52. package/dist/utils/extend-config.d.ts +1 -1
  53. package/dist/utils/extend-config.mjs +27 -14
  54. package/dist/utils/generate-css.cjs +13 -0
  55. package/dist/utils/generate-css.d.ts +2 -0
  56. package/dist/utils/generate-css.mjs +11 -0
  57. package/dist/utils/hex-to-rgb.cjs +1 -1
  58. package/dist/utils/hex-to-rgb.d.ts +1 -1
  59. package/dist/utils/hex-to-rgb.mjs +1 -1
  60. package/dist/utils/is-core-rule.cjs +9 -0
  61. package/dist/utils/is-core-rule.d.ts +1 -0
  62. package/dist/utils/is-core-rule.mjs +7 -0
  63. package/dist/{functions → utils}/reorder-for-readable-classes.cjs +12 -18
  64. package/dist/{functions → utils}/reorder-for-readable-classes.d.ts +1 -5
  65. package/dist/{functions → utils}/reorder-for-readable-classes.mjs +13 -19
  66. package/package.json +1 -1
  67. package/dist/config/media-queries.cjs +0 -7
  68. package/dist/config/media-queries.d.ts +0 -1
  69. package/dist/config/media-queries.mjs +0 -1
  70. package/dist/constants/base-unit-regex.cjs +0 -5
  71. package/dist/constants/base-unit-regex.d.ts +0 -1
  72. package/dist/constants/base-unit-regex.mjs +0 -3
  73. package/dist/constants/start-symbol.cjs +0 -10
  74. package/dist/constants/start-symbol.d.ts +0 -6
  75. package/dist/constants/start-symbol.mjs +0 -8
  76. package/dist/functions/transform-color-with-opacity.cjs +0 -9
  77. package/dist/functions/transform-color-with-opacity.d.ts +0 -1
  78. package/dist/functions/transform-color-with-opacity.mjs +0 -7
  79. package/dist/utils/concat-arrays.cjs +0 -12
  80. package/dist/utils/concat-arrays.d.ts +0 -1
  81. package/dist/utils/concat-arrays.mjs +0 -10
  82. package/dist/utils/get-type.cjs +0 -12
  83. package/dist/utils/get-type.d.ts +0 -7
  84. package/dist/utils/get-type.mjs +0 -10
  85. package/dist/utils/is-plain-object.cjs +0 -15
  86. package/dist/utils/is-plain-object.d.ts +0 -8
  87. package/dist/utils/is-plain-object.mjs +0 -13
  88. package/dist/utils/is-symbol.cjs +0 -14
  89. package/dist/utils/is-symbol.d.ts +0 -7
  90. package/dist/utils/is-symbol.mjs +0 -12
  91. package/dist/utils/rgb-to-hex.cjs +0 -7
  92. package/dist/utils/rgb-to-hex.d.ts +0 -1
  93. package/dist/utils/rgb-to-hex.mjs +0 -5
package/dist/core.cjs CHANGED
@@ -16,19 +16,17 @@ 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
- this.config = extendConfig.extendConfig(index.config, customConfig);
27
+ this.config = extendConfig(index.config, customConfig);
30
28
  } else {
31
- this.config = extendConfig.extendConfig(customConfig);
29
+ this.config = extendConfig(customConfig);
32
30
  }
33
31
  this.resolve();
34
32
  if (this.constructor === MasterCSS) {
@@ -40,10 +38,9 @@ class MasterCSS {
40
38
  this.stylesBy = {};
41
39
  this.selectors = {};
42
40
  this.variables = {};
43
- this.mediaQueries = {};
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, mediaQueries, 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,109 +79,124 @@ class MasterCSS {
82
79
  }
83
80
  if (variables) {
84
81
  const unexecutedAliasVariable = {};
85
- const parseVariable = (variable, name, theme)=>{
86
- if (!variable) return;
87
- const addVariable = (name, variableValue, replacedTheme, 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
- const currentTheme = replacedTheme ?? theme;
100
- if (currentTheme !== undefined) {
101
- if (Object.prototype.hasOwnProperty.call(this.variables, name)) {
102
- const variable = this.variables[name];
103
- if (currentTheme) {
104
- if (!variable.themes) {
105
- variable.themes = {};
102
+ const currentMode = replacedMode ?? mode;
103
+ if (currentMode !== undefined) {
104
+ if (Object.prototype.hasOwnProperty.call(this.variables, flatName)) {
105
+ const foundVariable = this.variables[flatName];
106
+ if (currentMode) {
107
+ if (!foundVariable.modes) {
108
+ foundVariable.modes = {};
106
109
  }
107
- variable.themes[currentTheme] = 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
- if (currentTheme) {
118
+ if (currentMode) {
116
119
  const newVariable = {
117
- type: variableValue.type,
118
- themes: {
119
- [currentTheme]: variableValue
120
+ key: variable.key,
121
+ name: variable.name,
122
+ group: variable.group,
123
+ type: variable.type,
124
+ modes: {
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][theme] = ()=>{
167
- delete unexecutedAliasVariable[name][theme];
168
- const [alias, aliasTheme] = aliasResult[1].split('@');
178
+ unexecutedAliasVariable[flatName][mode] = ()=>{
179
+ delete unexecutedAliasVariable[flatName][mode];
180
+ const [alias, aliasMode] = aliasResult[1].split('@');
169
181
  if (alias) {
170
182
  if (Object.prototype.hasOwnProperty.call(unexecutedAliasVariable, alias)) {
171
- for (const theme of Object.keys(unexecutedAliasVariable[alias])){
172
- unexecutedAliasVariable[alias][theme]?.();
183
+ for (const mode of Object.keys(unexecutedAliasVariable[alias])){
184
+ unexecutedAliasVariable[alias][mode]?.();
173
185
  }
174
186
  }
175
187
  const aliasVariable = this.variables[alias];
176
188
  if (aliasVariable) {
177
- if (aliasTheme === undefined && aliasVariable.themes) {
189
+ if (aliasMode === undefined && aliasVariable.modes) {
178
190
  addVariable(name, {
179
191
  type: aliasVariable.type,
180
192
  value: aliasVariable.value,
181
193
  space: aliasVariable.space
182
194
  }, '', aliasResult[2]);
183
- for(const theme in aliasVariable.themes){
184
- addVariable(name, aliasVariable.themes[theme], theme, aliasResult[2]);
195
+ for(const mode in aliasVariable.modes){
196
+ addVariable(name, aliasVariable.modes[mode], mode, aliasResult[2]);
185
197
  }
186
198
  } else {
187
- const variable = aliasTheme !== undefined ? aliasVariable.themes?.[aliasTheme] : aliasVariable;
199
+ const variable = aliasMode !== undefined ? aliasVariable.modes?.[aliasMode] : aliasVariable;
188
200
  if (variable) {
189
201
  const newVariable = {
190
202
  type: variable.type,
@@ -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,16 +248,19 @@ 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
- for (const theme of Object.keys(unexecutedAliasVariable[name])){
243
- unexecutedAliasVariable[name][theme]?.();
257
+ for (const mode of Object.keys(unexecutedAliasVariable[name])){
258
+ unexecutedAliasVariable[name][mode]?.();
244
259
  }
245
260
  }
246
261
  }
247
- if (mediaQueries) {
248
- this.mediaQueries = flattenObject.flattenObject(mediaQueries);
262
+ if (queries) {
263
+ this.queries = flattenObject.flattenObject(queries);
249
264
  }
250
265
  if (animations) {
251
266
  for(const animationName in animations){
@@ -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,20 +460,25 @@ 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
- this.config = extendConfig.extendConfig(index.config, customConfig);
478
+ this.config = extendConfig(index.config, customConfig);
419
479
  } else {
420
480
  // @ts-ignore
421
- this.config = extendConfig.extendConfig(customConfig);
481
+ this.config = extendConfig(customConfig);
422
482
  }
423
483
  this.resolve();
424
484
  this.rules.length = 0;
@@ -495,15 +555,15 @@ class MasterCSS {
495
555
  const variable = this.variables[eachVariableName];
496
556
  if (!variable.usage) variable.usage = 0;
497
557
  if (!--variable.usage) {
498
- const removeProperty = (theme)=>{
499
- const nativeRule = this.variablesNativeRules[theme];
558
+ const removeProperty = (mode)=>{
559
+ const nativeRule = this.variablesNativeRules[mode];
500
560
  nativeRule.cssRule.style.removeProperty('--' + eachVariableName);
501
561
  if (!nativeRule.cssRule.style.length) {
502
562
  const variablesRule = this.rules[0];
503
563
  const index = variablesRule.natives.indexOf(nativeRule);
504
564
  sheet?.deleteRule(index);
505
565
  variablesRule.natives.splice(index, 1);
506
- delete this.variablesNativeRules[theme];
566
+ delete this.variablesNativeRules[mode];
507
567
  if (!variablesRule.natives.length) {
508
568
  this.rules.splice(0, 1);
509
569
  this.variablesNativeRules = {};
@@ -513,9 +573,9 @@ class MasterCSS {
513
573
  if (variable.value) {
514
574
  removeProperty('');
515
575
  }
516
- if (variable.themes) {
517
- for(const theme in variable.themes){
518
- removeProperty(theme);
576
+ if (variable.modes) {
577
+ for(const mode in variable.modes){
578
+ removeProperty(mode);
519
579
  }
520
580
  }
521
581
  }
@@ -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
  }
@@ -578,7 +638,7 @@ class MasterCSS {
578
638
  * @example <1 <2 <3 ALL >=1 >=2 >=3
579
639
  * @description
580
640
  */ const endIndex = this.rules.length - 1;
581
- const { media, order, priority, hasWhere, className } = rule;
641
+ const { at, atToken, order, priority, hasWhere, className } = rule;
582
642
  const findIndex = (startIndex, stopCheck, matchCheck)=>{
583
643
  let i = startIndex;
584
644
  for(; i <= endIndex; i++){
@@ -590,14 +650,15 @@ class MasterCSS {
590
650
  };
591
651
  let matchStartIndex;
592
652
  let matchEndIndex;
593
- if (media) {
594
- const mediaStartIndex = this.rules.findIndex((eachRule)=>eachRule.media);
653
+ if (atToken) {
654
+ const mediaStartIndex = this.rules.findIndex((eachRule)=>eachRule.at?.media);
595
655
  if (mediaStartIndex === -1) {
596
656
  index = endIndex + 1;
597
657
  } else {
598
- const { 'max-width': maxWidthFeature, 'min-width': minWidthFeature } = media.features;
658
+ const maxWidthFeature = at.media?.find(({ name })=>name === 'max-width');
659
+ const minWidthFeature = at.media?.find(({ name })=>name === 'min-width');
599
660
  if (maxWidthFeature || minWidthFeature) {
600
- const mediaWidthStartIndex = this.rules.findIndex((eachRule)=>eachRule.media?.features['max-width'] || eachRule.media?.features['min-width']);
661
+ const mediaWidthStartIndex = this.rules.findIndex((eachRule)=>eachRule.at?.media?.find(({ name })=>name === 'max-width' || name === 'min-width'));
601
662
  if (mediaWidthStartIndex === -1) {
602
663
  index = endIndex + 1;
603
664
  } else {
@@ -608,10 +669,10 @@ class MasterCSS {
608
669
  * find 第一個所遇到同樣 feature 且範圍值比自己大的 rule,
609
670
  * 並插入在該 rule 之後,讓自己優先被套用
610
671
  */ if (priority === -1) {
611
- matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.priority !== -1, (eachRule)=>eachRule.media.features['max-width'] && eachRule.media.features['min-width']);
672
+ matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.priority !== -1, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width'));
612
673
  matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.priority !== -1);
613
674
  } else {
614
- matchStartIndex = findIndex(mediaWidthStartIndex, undefined, (eachRule)=>eachRule.media.features['max-width'] && eachRule.media.features['min-width'] && eachRule.priority !== -1);
675
+ matchStartIndex = findIndex(mediaWidthStartIndex, undefined, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1);
615
676
  matchEndIndex = endIndex;
616
677
  }
617
678
  if (matchStartIndex !== -1) {
@@ -620,7 +681,9 @@ class MasterCSS {
620
681
  const endI = matchStartIndex;
621
682
  matchStartIndex = undefined;
622
683
  for(; i >= endI; i--){
623
- const { 'max-width': eachMaxWidthFeature, 'min-width': eachMinWidthFeature } = this.rules[i].media.features;
684
+ const eachRule = this.rules[i];
685
+ const eachMaxWidthFeature = eachRule.at.media?.find(({ name })=>name === 'max-width');
686
+ const eachMinWidthFeature = eachRule.at.media?.find(({ name })=>name === 'min-width');
624
687
  const eachRange = eachMaxWidthFeature.value - eachMinWidthFeature.value;
625
688
  if (eachRange < range) {
626
689
  matchEndIndex = i - 1;
@@ -634,7 +697,9 @@ class MasterCSS {
634
697
  if (matchStartIndex !== -1 && matchStartIndex !== undefined) {
635
698
  const range = maxWidthFeature.value - minWidthFeature.value;
636
699
  for(let i = matchEndIndex; i >= matchStartIndex; i--){
637
- const { 'max-width': eachMaxWidthFeature, 'min-width': eachMinWidthFeature } = this.rules[i].media.features;
700
+ const eachRule = this.rules[i];
701
+ const eachMaxWidthFeature = eachRule.at.media?.find(({ name })=>name === 'max-width');
702
+ const eachMinWidthFeature = eachRule.at.media?.find(({ name })=>name === 'min-width');
638
703
  const eachRange = eachMaxWidthFeature.value - eachMinWidthFeature.value;
639
704
  if (eachRange < range) {
640
705
  matchEndIndex = i - 1;
@@ -649,15 +714,15 @@ class MasterCSS {
649
714
  * find 第一個所遇到同樣 feature 且值比自己大的 rule,
650
715
  * 並插入在該 rule 之後,讓自己優先被套用
651
716
  */ if (priority === -1) {
652
- matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media.features['max-width'] && eachRule.media.features['min-width'] || eachRule.priority !== -1, (eachRule)=>!eachRule.media.features['max-width'] && eachRule.media.features['min-width']);
653
- matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media.features['max-width'] && eachRule.media.features['min-width'] || eachRule.priority !== -1);
717
+ matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') || eachRule.priority !== -1, (eachRule)=>!eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width'));
718
+ matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') || eachRule.priority !== -1);
654
719
  } else {
655
- matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media.features['max-width'] && eachRule.media.features['min-width'] && eachRule.priority !== -1, (eachRule)=>!eachRule.media.features['max-width'] && eachRule.media.features['min-width'] && eachRule.priority !== -1);
656
- matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media.features['max-width'] && eachRule.media.features['min-width'] && eachRule.priority !== -1);
720
+ matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1, (eachRule)=>!eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1);
721
+ matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1);
657
722
  }
658
723
  if (matchStartIndex !== -1) {
659
724
  for(let i = matchEndIndex; i >= matchStartIndex; i--){
660
- const value = this.rules[i].media.features['min-width'].value;
725
+ const value = (this.rules[i].at.media?.find(({ name })=>name === 'min-width')).value;
661
726
  if (value > minWidthFeature.value) {
662
727
  matchEndIndex = i - 1;
663
728
  } else if (value < minWidthFeature.value) {
@@ -671,15 +736,15 @@ class MasterCSS {
671
736
  * find 第一個所遇到同樣 feature 且值比自己大的 rule,
672
737
  * 並插入在該 rule 之後,讓自己優先被套用
673
738
  */ if (priority === -1) {
674
- matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media.features['min-width'] || eachRule.priority !== -1, (eachRule)=>eachRule.media.features['max-width']);
675
- matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media.features['min-width'] || eachRule.priority !== -1);
739
+ matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'min-width') || eachRule.priority !== -1, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width'));
740
+ matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'min-width') || eachRule.priority !== -1);
676
741
  } else {
677
- matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media.features['min-width'] && eachRule.priority !== -1, (eachRule)=>eachRule.media.features['max-width'] && eachRule.priority !== -1);
678
- matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media.features['min-width'] && eachRule.priority !== -1);
742
+ matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.priority !== -1);
743
+ matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1);
679
744
  }
680
745
  if (matchStartIndex !== -1) {
681
746
  for(let i = matchEndIndex; i >= matchStartIndex; i--){
682
- const value = this.rules[i].media.features['max-width'].value;
747
+ const value = (this.rules[i].at.media?.find(({ name })=>name === 'max-width')).value;
683
748
  if (value < maxWidthFeature.value) {
684
749
  matchEndIndex = i - 1;
685
750
  } else if (value > maxWidthFeature.value) {
@@ -693,10 +758,10 @@ class MasterCSS {
693
758
  } else {
694
759
  if (priority === -1) {
695
760
  matchStartIndex = mediaStartIndex;
696
- matchEndIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.media?.features['max-width'] || eachRule.media?.features['min-width'] || eachRule.priority !== -1);
761
+ matchEndIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width') || eachRule.priority !== -1);
697
762
  } else {
698
- matchStartIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.media?.features['max-width'] || eachRule.media?.features['min-width'], (eachRule)=>eachRule.priority !== -1);
699
- matchEndIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.media?.features['max-width'] || eachRule.media?.features['min-width']);
763
+ matchStartIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width'), (eachRule)=>eachRule.priority !== -1);
764
+ matchEndIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width'));
700
765
  }
701
766
  }
702
767
  }
@@ -704,10 +769,10 @@ class MasterCSS {
704
769
  const findStartIndex = Object.keys(this.variablesNativeRules).length ? this.hasKeyframesRule ? 2 : 1 : this.hasKeyframesRule ? 1 : 0;
705
770
  if (priority === -1) {
706
771
  matchStartIndex = findStartIndex;
707
- matchEndIndex = findIndex(findStartIndex, (eachRule)=>eachRule.media || eachRule.priority !== -1);
772
+ matchEndIndex = findIndex(findStartIndex, (eachRule)=>eachRule.atToken || eachRule.priority !== -1);
708
773
  } else {
709
- matchStartIndex = findIndex(findStartIndex, (eachRule)=>eachRule.media, (eachRule)=>eachRule.priority !== -1);
710
- matchEndIndex = findIndex(findStartIndex, (eachRule)=>eachRule.media);
774
+ matchStartIndex = findIndex(findStartIndex, (eachRule)=>eachRule.atToken, (eachRule)=>eachRule.priority !== -1);
775
+ matchEndIndex = findIndex(findStartIndex, (eachRule)=>eachRule.atToken);
711
776
  }
712
777
  }
713
778
  if (index === undefined && matchEndIndex !== undefined && matchStartIndex !== undefined) {
@@ -751,7 +816,6 @@ class MasterCSS {
751
816
  }
752
817
  this.rules.splice(index, 0, rule);
753
818
  this.ruleBy[className] = rule;
754
- // 只在瀏覽器端運行
755
819
  if (this.style) {
756
820
  const sheet = this.style.sheet;
757
821
  let cssRuleIndex = 0;
@@ -787,6 +851,7 @@ class MasterCSS {
787
851
  // animations
788
852
  this.handleRuleWithAnimationNames(rule);
789
853
  rule.definition.insert?.call(rule);
854
+ return index;
790
855
  }
791
856
  get text() {
792
857
  return this.rules.map((eachRule)=>eachRule.text).join('');
@@ -850,23 +915,23 @@ class MasterCSS {
850
915
  if (variable.usage) {
851
916
  variable.usage++;
852
917
  } else {
853
- const addProperty = (theme, variableValue)=>{
854
- let nativeRule = this.variablesNativeRules[theme];
918
+ const addProperty = (mode, variable)=>{
919
+ let nativeRule = this.variablesNativeRules[mode];
855
920
  if (!nativeRule) {
856
921
  let cssRule;
857
922
  let mediaConditionText;
858
923
  let selectorText;
859
- if (theme) {
860
- switch(this.config.themeDriver){
924
+ if (mode) {
925
+ switch(this.config.modeDriver){
861
926
  case 'media':
862
- mediaConditionText = `@media(prefers-color-scheme:${theme})`;
927
+ mediaConditionText = `@media(prefers-color-scheme:${mode})`;
863
928
  selectorText = ':root';
864
929
  break;
865
930
  case 'host':
866
- selectorText = `:host(.${theme})`;
931
+ selectorText = `:host(.${mode})`;
867
932
  break;
868
933
  default:
869
- selectorText = `.${theme}`;
934
+ selectorText = `.${mode}`;
870
935
  break;
871
936
  }
872
937
  } else {
@@ -916,19 +981,19 @@ class MasterCSS {
916
981
  };
917
982
  }
918
983
  }
919
- nativeRule = this.pushVariableNativeRule(theme, cssRule);
984
+ nativeRule = this.pushVariableNativeRule(mode, cssRule);
920
985
  }
921
986
  const propertyName = '--' + eachVariableName;
922
987
  if (!initializing || !nativeRule.cssRule.style.getPropertyValue(propertyName)) {
923
- nativeRule.cssRule.style.setProperty(propertyName, String(variableValue.value));
988
+ nativeRule.cssRule.style.setProperty(propertyName, String(variable.value));
924
989
  }
925
990
  };
926
991
  if (variable.value) {
927
992
  addProperty('', variable);
928
993
  }
929
- if (variable.themes) {
930
- for(const theme in variable.themes){
931
- addProperty(theme, variable.themes[theme]);
994
+ if (variable.modes) {
995
+ for(const mode in variable.modes){
996
+ addProperty(mode, variable.modes[mode]);
932
997
  }
933
998
  }
934
999
  variable.usage = 1;
@@ -936,7 +1001,7 @@ class MasterCSS {
936
1001
  }
937
1002
  }
938
1003
  }
939
- pushVariableNativeRule(theme, variableCSSRule) {
1004
+ pushVariableNativeRule(mode, variableCSSRule) {
940
1005
  if (!Object.keys(this.variablesNativeRules).length) {
941
1006
  this.variablesNativeRules = {};
942
1007
  const newRule = {
@@ -965,7 +1030,7 @@ class MasterCSS {
965
1030
  return prefix + properties.join(';') + suffix;
966
1031
  }
967
1032
  };
968
- this.rules[0].natives.push(this.variablesNativeRules[theme] = nativeRule);
1033
+ this.rules[0].natives.push(this.variablesNativeRules[mode] = nativeRule);
969
1034
  return nativeRule;
970
1035
  }
971
1036
  }