@master/css 2.0.0-rc.67 → 2.0.0-rc.69

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 (109) hide show
  1. package/dist/common.cjs +0 -2
  2. package/dist/common.d.ts +0 -1
  3. package/dist/common.mjs +1 -2
  4. package/dist/config/functions.cjs +9 -243
  5. package/dist/config/functions.d.ts +137 -2
  6. package/dist/config/functions.mjs +9 -243
  7. package/dist/config/index.cjs +2 -2
  8. package/dist/config/index.mjs +2 -2
  9. package/dist/config/modes.cjs +307 -3
  10. package/dist/config/modes.d.ts +306 -2
  11. package/dist/config/modes.mjs +307 -3
  12. package/dist/config/rules.cjs +740 -782
  13. package/dist/config/rules.d.ts +692 -683
  14. package/dist/config/rules.mjs +741 -783
  15. package/dist/config/utilities.cjs +328 -97
  16. package/dist/config/utilities.d.ts +247 -16
  17. package/dist/config/utilities.mjs +328 -97
  18. package/dist/config/variables.cjs +88 -460
  19. package/dist/config/variables.d.ts +358 -369
  20. package/dist/config/variables.mjs +88 -460
  21. package/dist/core.cjs +242 -260
  22. package/dist/core.d.ts +5 -3
  23. package/dist/core.mjs +242 -260
  24. package/dist/create.cjs +10 -0
  25. package/dist/create.d.ts +3 -0
  26. package/dist/create.mjs +8 -0
  27. package/dist/declarers/core.group.cjs +99 -0
  28. package/dist/declarers/core.group.d.ts +2 -0
  29. package/dist/declarers/core.group.mjs +97 -0
  30. package/dist/declarers/core.variable.cjs +9 -0
  31. package/dist/declarers/core.variable.d.ts +4 -0
  32. package/dist/declarers/core.variable.mjs +7 -0
  33. package/dist/declarers/index.cjs +13 -0
  34. package/dist/declarers/index.d.ts +10 -0
  35. package/dist/declarers/index.mjs +11 -0
  36. package/dist/declarers/pair.cjs +12 -0
  37. package/dist/declarers/pair.d.ts +4 -0
  38. package/dist/declarers/pair.mjs +10 -0
  39. package/dist/factories/with-syntax-layer.cjs +0 -2
  40. package/dist/factories/with-syntax-layer.mjs +0 -2
  41. package/dist/function-transformers/core.calc.cjs +225 -0
  42. package/dist/function-transformers/core.calc.d.ts +2 -0
  43. package/dist/function-transformers/core.calc.mjs +223 -0
  44. package/dist/function-transformers/core.variable.cjs +23 -0
  45. package/dist/function-transformers/core.variable.d.ts +7 -0
  46. package/dist/function-transformers/core.variable.mjs +21 -0
  47. package/dist/function-transformers/index.cjs +11 -0
  48. package/dist/function-transformers/index.d.ts +8 -0
  49. package/dist/function-transformers/index.mjs +9 -0
  50. package/dist/index.cjs +10 -1
  51. package/dist/index.d.ts +8 -2
  52. package/dist/index.mjs +6 -1
  53. package/dist/layer.cjs +2 -4
  54. package/dist/layer.mjs +2 -4
  55. package/dist/non-layer.cjs +2 -4
  56. package/dist/non-layer.mjs +2 -4
  57. package/dist/syntax-rule-type.cjs +8 -7
  58. package/dist/syntax-rule-type.d.ts +7 -7
  59. package/dist/syntax-rule-type.mjs +8 -7
  60. package/dist/syntax-rule.cjs +305 -253
  61. package/dist/syntax-rule.d.ts +2 -2
  62. package/dist/syntax-rule.mjs +306 -254
  63. package/dist/{utils/autofill-solid-style.cjs → transformers/auto-fill-solid.cjs} +3 -3
  64. package/dist/transformers/auto-fill-solid.d.ts +2 -0
  65. package/dist/{utils/autofill-solid-style.mjs → transformers/auto-fill-solid.mjs} +3 -3
  66. package/dist/transformers/index.cjs +9 -0
  67. package/dist/transformers/index.d.ts +6 -0
  68. package/dist/transformers/index.mjs +7 -0
  69. package/dist/types/common.d.ts +0 -2
  70. package/dist/types/config.d.ts +24 -20
  71. package/dist/types/syntax.d.ts +10 -8
  72. package/dist/utils/equal-selectors.cjs +1 -2
  73. package/dist/utils/equal-selectors.mjs +1 -2
  74. package/dist/utils/extend-config.cjs +83 -44
  75. package/dist/utils/extend-config.d.ts +10 -1
  76. package/dist/utils/extend-config.mjs +83 -44
  77. package/dist/utils/flatten-meta-object.cjs +38 -0
  78. package/dist/utils/flatten-meta-object.d.ts +13 -0
  79. package/dist/utils/flatten-meta-object.mjs +36 -0
  80. package/dist/utils/flatten-object.cjs +13 -9
  81. package/dist/utils/flatten-object.d.ts +1 -1
  82. package/dist/utils/flatten-object.mjs +13 -9
  83. package/dist/utils/generate-css.cjs +2 -2
  84. package/dist/utils/generate-css.d.ts +1 -2
  85. package/dist/utils/generate-css.mjs +2 -2
  86. package/dist/utils/generate-selector.cjs +2 -1
  87. package/dist/utils/generate-selector.mjs +2 -1
  88. package/dist/utils/minify-extended-config.cjs +64 -0
  89. package/dist/utils/minify-extended-config.d.ts +9 -0
  90. package/dist/utils/minify-extended-config.mjs +62 -0
  91. package/dist/utils/nest-meta-object.cjs +25 -0
  92. package/dist/utils/nest-meta-object.d.ts +7 -0
  93. package/dist/utils/nest-meta-object.mjs +23 -0
  94. package/dist/utils/parse-at.cjs +1 -2
  95. package/dist/utils/parse-at.d.ts +2 -2
  96. package/dist/utils/parse-at.mjs +1 -2
  97. package/dist/utils/parse-pair.cjs +3 -6
  98. package/dist/utils/parse-pair.mjs +3 -6
  99. package/dist/utils/parse-selector.cjs +6 -6
  100. package/dist/utils/parse-selector.d.ts +3 -3
  101. package/dist/utils/parse-selector.mjs +6 -6
  102. package/dist/utils/sort-readable-classes.cjs +2 -2
  103. package/dist/utils/sort-readable-classes.d.ts +1 -2
  104. package/dist/utils/sort-readable-classes.mjs +2 -2
  105. package/dist/variable-rule.cjs +35 -29
  106. package/dist/variable-rule.d.ts +16 -6
  107. package/dist/variable-rule.mjs +35 -29
  108. package/package.json +1 -1
  109. package/dist/utils/autofill-solid-style.d.ts +0 -3
package/dist/core.cjs CHANGED
@@ -1,9 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var syntaxRule = require('./syntax-rule.cjs');
4
- var index = require('./config/index.cjs');
5
4
  var hexToRgb = require('./utils/hex-to-rgb.cjs');
6
- var flattenObject = require('./utils/flatten-object.cjs');
7
5
  var extendConfig = require('./utils/extend-config.cjs');
8
6
  var rule = require('./rule.cjs');
9
7
  var syntaxRuleType = require('./syntax-rule-type.cjs');
@@ -17,42 +15,29 @@ var parseSelector = require('./utils/parse-selector.cjs');
17
15
 
18
16
  class MasterCSS {
19
17
  customConfig;
20
- static config = index.config;
21
- definedRules;
18
+ baseConfig;
19
+ definedRules = [];
22
20
  config;
23
- layerStatementRule;
24
- rules;
25
- classRules;
26
- animationsNonLayer;
27
- baseLayer;
28
- themeLayer;
29
- presetLayer;
30
- componentsLayer;
31
- generalLayer;
32
- components;
33
- selectors;
34
- variables;
35
- atRules;
36
- animations;
37
- constructor(customConfig){
21
+ layerStatementRule = new rule.Rule('layer-statement', '@layer base,theme,preset,components,general;');
22
+ rules = [
23
+ this.layerStatementRule
24
+ ];
25
+ classRules = new Map();
26
+ animationsNonLayer = new nonLayer(this);
27
+ baseLayer = new syntaxLayer('base', this);
28
+ themeLayer = new layer('theme', this);
29
+ presetLayer = new syntaxLayer('preset', this);
30
+ componentsLayer = new syntaxLayer('components', this);
31
+ generalLayer = new syntaxLayer('general', this);
32
+ components = new Map();
33
+ selectors = new Map();
34
+ variables = new Map();
35
+ modes = [];
36
+ atRules = new Map();
37
+ animations = new Map();
38
+ constructor(customConfig, baseConfig){
38
39
  this.customConfig = customConfig;
39
- this.definedRules = [];
40
- this.layerStatementRule = new rule.Rule('layer-statement', '@layer base,theme,preset,components,general;');
41
- this.rules = [
42
- this.layerStatementRule
43
- ];
44
- this.classRules = new Map();
45
- this.animationsNonLayer = new nonLayer(this);
46
- this.baseLayer = new syntaxLayer('base', this);
47
- this.themeLayer = new layer('theme', this);
48
- this.presetLayer = new syntaxLayer('preset', this);
49
- this.componentsLayer = new syntaxLayer('components', this);
50
- this.generalLayer = new syntaxLayer('general', this);
51
- this.components = new Map();
52
- this.selectors = new Map();
53
- this.variables = new Map();
54
- this.atRules = new Map();
55
- this.animations = new Map();
40
+ this.baseConfig = baseConfig;
56
41
  this.resolve(customConfig);
57
42
  }
58
43
  get text() {
@@ -77,7 +62,7 @@ class MasterCSS {
77
62
  customConfig = this.customConfig;
78
63
  }
79
64
  // @ts-expect-error read-only
80
- this.config = customConfig?.override ? extendConfig(customConfig) : extendConfig(index.config, customConfig);
65
+ this.config = this.baseConfig ? extendConfig(this.baseConfig, customConfig) : extendConfig(customConfig);
81
66
  this.resolveVariables();
82
67
  this.resolveAnimations();
83
68
  this.resolveSelectors();
@@ -127,23 +112,25 @@ class MasterCSS {
127
112
  rulesEntries.push(...Object.entries(rules));
128
113
  }
129
114
  const rulesEntriesLength = rulesEntries.length;
130
- // Prepare color variables
131
- const colorNames = new Set([
132
- 'current',
133
- 'currentColor',
134
- 'transparent'
135
- ]);
136
- this.variables.forEach((v)=>{
137
- if (v.type === 'color') colorNames.add(v.name);
138
- });
139
- const colorPattern = [
140
- ...colorNames
141
- ].join('|');
142
115
  // Main loop
143
116
  rulesEntries.sort((a, b)=>{
144
117
  if (a[1].type !== b[1].type) {
145
118
  return (b[1].type || 0) - (a[1].type || 0);
146
119
  }
120
+ if (a[1].kind !== b[1].kind) {
121
+ if (!a[1].kind) return 1;
122
+ if (!b[1].kind) return -1;
123
+ const kindOrder = [
124
+ 'color',
125
+ 'number',
126
+ 'image'
127
+ ];
128
+ const aKindIndex = kindOrder.indexOf(a[1].kind);
129
+ const bKindIndex = kindOrder.indexOf(b[1].kind);
130
+ if (aKindIndex !== bKindIndex) {
131
+ return aKindIndex - bKindIndex;
132
+ }
133
+ }
147
134
  return b[0].localeCompare(a[0], undefined, {
148
135
  numeric: true
149
136
  });
@@ -152,7 +139,6 @@ class MasterCSS {
152
139
  const syntax = {
153
140
  id,
154
141
  keys: [],
155
- variables: {},
156
142
  matchers: {},
157
143
  order,
158
144
  definition: def
@@ -162,25 +148,42 @@ class MasterCSS {
162
148
  ','
163
149
  ];
164
150
  this.definedRules.push(syntax);
165
- const { matcher, type, subkey, ambiguousKeys, ambiguousValues, sign, key: originalKey, variables: ruleVariableGroups } = def;
151
+ let { matcher, type, subkey, aliasGroups, values, kind, sign, key: originalKey, namespaces } = def;
166
152
  const keys = [];
167
153
  let key = originalKey;
168
154
  // Helper: resolve variable groups
169
- const addResolvedVariables = (groupName)=>{
155
+ const addNamespace = (namespace)=>{
156
+ const dashedNamespace = namespace.replace(/\./g, '-');
170
157
  this.variables.forEach((v)=>{
171
- if (v.group === groupName) {
172
- syntax.variables[v.key] = v;
158
+ if (v.namespace === namespace || v.group === namespace) {
159
+ let variableKey = v.name;
160
+ if (variableKey.startsWith('-' + dashedNamespace) || variableKey.startsWith(dashedNamespace)) {
161
+ variableKey = variableKey.slice(dashedNamespace.length + 1);
162
+ }
163
+ if (syntax.variables) {
164
+ syntax.variables.set(variableKey, v);
165
+ } else {
166
+ syntax.variables = new Map([
167
+ [
168
+ variableKey,
169
+ v
170
+ ]
171
+ ]);
172
+ }
173
173
  }
174
174
  });
175
175
  };
176
- // Rule-defined variable groups
177
- if (ruleVariableGroups) {
178
- ruleVariableGroups.forEach(addResolvedVariables);
176
+ // 1. Auto variable binding
177
+ addNamespace(id);
178
+ // 2. Rule-defined variable groups
179
+ if (namespaces) {
180
+ namespaces.forEach(addNamespace);
179
181
  }
180
- // Auto variable binding
181
- addResolvedVariables(id);
182
- // Key derivation logic
183
- if (type === syntaxRuleType.NativeShorthand || type === syntaxRuleType.Native) {
182
+ if (id.endsWith('()')) {
183
+ if (!key) def.key = key = id;
184
+ const fnName = id.slice(0, -2);
185
+ matcher = new RegExp(`^${fnName}\\(`);
186
+ } else if (type === syntaxRuleType.NativeShorthand || type === syntaxRuleType.Native) {
184
187
  if (!key) def.key = key = id;
185
188
  keys.push(id);
186
189
  }
@@ -195,19 +198,30 @@ class MasterCSS {
195
198
  if (type === syntaxRuleType.Shorthand) keys.push(id);
196
199
  }
197
200
  // Ambiguous keys and values
198
- if (ambiguousKeys?.length) {
199
- const keyPattern = ambiguousKeys.length > 1 ? `(?:${ambiguousKeys.join('|')})` : ambiguousKeys[0];
200
- const variableKeys = Object.keys(syntax.variables);
201
- if (ambiguousValues?.length) {
202
- const valuePatterns = ambiguousValues.map((val)=>val instanceof RegExp ? val.source.replace('\\$colors', colorPattern) : `${val}(?:\\b|_)`);
201
+ if (aliasGroups?.length) {
202
+ const keyPattern = aliasGroups.length > 1 ? `(?:${aliasGroups.join('|')})` : aliasGroups[0];
203
+ const variableKeys = Array.from(syntax.variables?.keys() || []);
204
+ const valuePatterns = values ? values.map((v)=>`${v}(?:\\b|_)`) : [];
205
+ switch(kind){
206
+ case 'color':
207
+ valuePatterns.push(`(?:#|(?:color|color-contrast|color-mix|hwb|lab|lch|oklab|oklch|rgb|rgba|hsl|hsla|light-dark)\\(.*\\)|(?:currentColor|transparent)(?![a-zA-Z0-9-]))`);
208
+ break;
209
+ case 'number':
210
+ valuePatterns.push('(?:[\\d.]|(?:max|min|calc|clamp)\\([^|]*\\))');
211
+ break;
212
+ case 'image':
213
+ valuePatterns.push('(?:url|linear-gradient|radial-gradient|repeating-linear-gradient|repeating-radial-gradient|conic-gradient)\\(.*\\)');
214
+ break;
215
+ }
216
+ if (valuePatterns?.length) {
203
217
  syntax.matchers.value = new RegExp(`^${keyPattern}:(?:${valuePatterns.join('|')})[^|]*?(?:@|$)`);
204
218
  }
205
219
  if (variableKeys.length) {
206
- syntax.matchers.variable = new RegExp(`^${keyPattern}:(?:${variableKeys.join('|')}(?![a-zA-Z0-9-]))[^|]*?(?:@|$)`);
220
+ syntax.matchers.variable = new RegExp(`^${keyPattern}:(?:${variableKeys.join('|')})(?![a-zA-Z0-9-])[^|]*?(?:@|$)`);
207
221
  }
208
222
  }
209
223
  } else {
210
- syntax.matchers.arbitrary = matcher;
224
+ syntax.matchers.arbitrary = new RegExp(matcher);
211
225
  }
212
226
  // Utility rule matcher
213
227
  if (type === syntaxRuleType.Utility) {
@@ -222,16 +236,15 @@ class MasterCSS {
222
236
  });
223
237
  }
224
238
  resolveComponents() {
225
- const { components } = this.config;
226
- const flatComps = components ? flattenObject.flattenObject(components) : {};
227
- const flatNames = Object.keys(flatComps);
239
+ const { components = {} } = this.config;
240
+ const flatNames = Object.keys(components);
228
241
  const resolve = (name, currentClasses = [])=>{
229
242
  const compClasses = this.components.get(name);
230
243
  if (compClasses) {
231
244
  currentClasses.push(...compClasses);
232
245
  return;
233
246
  }
234
- const className = flatComps[name];
247
+ const className = components[name];
235
248
  if (!className) return;
236
249
  const classes = className.replace(/(?:\n\s*)+/g, ' ').trim().split(' ');
237
250
  for (const cls of classes){
@@ -249,32 +262,12 @@ class MasterCSS {
249
262
  for (const name of flatNames){
250
263
  resolve(name);
251
264
  }
252
- // Second pass: convert to grouped syntax rule strings
253
- this.components.forEach((compClasses, componentName)=>{
254
- const syntaxRulesByStateToken = {};
255
- for (const syntax of compClasses){
256
- const parsed = this.create(syntax);
257
- if (parsed?.valid) {
258
- const group = syntaxRulesByStateToken[parsed.stateToken] ||= [];
259
- group.push(parsed);
260
- } else {
261
- console.error(`Invalid class "${syntax}" found in ${componentName} component.`);
262
- }
263
- }
264
- const result = Object.entries(syntaxRulesByStateToken).map(([stateToken, syntaxRules])=>{
265
- if (syntaxRules.length === 1) return syntaxRules[0].name;
266
- const namesWithoutToken = syntaxRules.map((s)=>s.name.slice(0, s.name.length - s.stateToken.length));
267
- return `{${namesWithoutToken.join(';')}}${stateToken}`;
268
- });
269
- this.components.set(componentName, result);
270
- });
271
265
  }
272
266
  resolveSelectors() {
273
267
  const { selectors } = this.config;
274
268
  if (selectors) {
275
- const flatSelectors = flattenObject.flattenObject(selectors);
276
- for(const token in flatSelectors){
277
- const value = flatSelectors[token];
269
+ for(const token in selectors){
270
+ const value = selectors[token];
278
271
  const nodes = parseSelector(value, this, false);
279
272
  this.selectors.set(token, nodes);
280
273
  }
@@ -295,9 +288,8 @@ class MasterCSS {
295
288
  }
296
289
  }
297
290
  if (at) {
298
- const flatAt = flattenObject.flattenObject(at);
299
- for(const token in flatAt){
300
- const value = flatAt[token];
291
+ for(const token in at){
292
+ const value = at[token];
301
293
  if (typeof value === 'number') {
302
294
  const node = this.parseValue(value);
303
295
  this.atRules.set(token, {
@@ -314,194 +306,187 @@ class MasterCSS {
314
306
  }
315
307
  }
316
308
  resolveVariables() {
317
- const { variables, screens } = this.config;
309
+ const { variables, screens, modes } = this.config;
318
310
  const aliasVariableModeResolvers = new Map();
319
- const resolveVariable = (variableDefinition, name, mode)=>{
320
- if (variableDefinition === undefined || variableDefinition === null) return;
321
- const addVariable = (name, variable, replacedMode, alpha)=>{
322
- if (variable === undefined) return;
323
- const flatName = name.join('-');
324
- const groups = name.slice(0, -1).filter(Boolean);
325
- const key = (name[0] === '' ? '-' : '') + name[name.length - 1];
326
- variable.key = key;
327
- variable.name = flatName;
328
- if (groups.length) variable.group = groups.join('.');
329
- if (variable.type === 'color') {
330
- if (alpha) {
331
- const slashIndex = variable.value.indexOf('/');
332
- variable = {
333
- ...variable,
334
- 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)
335
- };
336
- }
337
- }
338
- const currentMode = replacedMode ?? mode;
339
- if (currentMode !== undefined) {
340
- const foundVariable = this.variables.get(flatName);
311
+ const resolveVariable = (variable, mode)=>{
312
+ const addVariable = (name, newVariable, currentMode)=>{
313
+ if (currentMode) {
314
+ const foundVariable = this.variables.get(name);
315
+ const newModeVariable = {
316
+ value: newVariable.value
317
+ };
318
+ if ('alpha' in newVariable) newModeVariable.alpha = newVariable.alpha;
319
+ if ('space' in newVariable) newModeVariable.space = newVariable.space;
341
320
  if (foundVariable) {
342
- if (currentMode) {
343
- if (!foundVariable.modes) {
344
- foundVariable.modes = {};
345
- }
346
- foundVariable.modes[currentMode] = variable;
347
- } else {
348
- foundVariable.value = variable.value;
349
- if (variable.type === 'color') {
350
- foundVariable.space = variable.space;
351
- }
321
+ if (newVariable.type && newVariable.type !== foundVariable.type) {
322
+ return;
352
323
  }
324
+ if (!foundVariable.modes) foundVariable.modes = {};
325
+ foundVariable.modes[currentMode] = newModeVariable;
353
326
  } else {
354
- if (currentMode) {
355
- const newVariable = {
356
- key: variable.key,
357
- name: variable.name,
358
- group: variable.group,
359
- type: variable.type,
360
- modes: {
361
- [currentMode]: variable
362
- }
363
- };
364
- if (variable.type === 'color') {
365
- newVariable.space = variable.space;
327
+ const newRootVaraible = {
328
+ name: newVariable.name,
329
+ key: newVariable.key,
330
+ type: newVariable.type,
331
+ modes: {
332
+ [currentMode]: newModeVariable
366
333
  }
367
- this.variables.set(flatName, newVariable);
368
- } else {
369
- this.variables.set(flatName, variable);
370
- }
334
+ };
335
+ if (newVariable.namespace) newRootVaraible.namespace = newVariable.namespace;
336
+ if (newVariable.group) newRootVaraible.group = newVariable.group;
337
+ this.variables.set(name, newRootVaraible);
371
338
  }
372
339
  } else {
373
- this.variables.set(flatName, variable);
340
+ this.variables.set(name, newVariable);
374
341
  }
375
342
  };
376
- if (typeof variableDefinition === 'object') {
377
- if (Array.isArray(variableDefinition)) {
378
- addVariable(name, {
379
- type: 'string',
380
- value: variableDefinition.join(',')
381
- });
382
- } else {
383
- const keys = Object.keys(variableDefinition);
384
- for (const eachKey of keys){
385
- if (eachKey === '' || eachKey.startsWith('@')) {
386
- resolveVariable(variableDefinition[eachKey], name, eachKey || keys.some((eachKey)=>eachKey.startsWith('@')) ? eachKey.slice(1) : undefined);
387
- } else {
388
- resolveVariable(variableDefinition[eachKey], [
389
- ...name,
390
- eachKey
391
- ]);
392
- }
393
- }
394
- }
395
- } else if (typeof variableDefinition === 'number') {
396
- addVariable(name, {
397
- type: 'number',
398
- value: variableDefinition
399
- });
400
- addVariable([
401
- '',
402
- ...name
403
- ], {
343
+ if (typeof variable.value === 'number') {
344
+ addVariable(variable.name, {
345
+ ...variable,
346
+ type: 'number'
347
+ }, mode);
348
+ addVariable('-' + variable.name, {
349
+ ...variable,
404
350
  type: 'number',
405
- value: variableDefinition * -1
406
- });
407
- } else if (typeof variableDefinition === 'string') {
408
- const aliasResult = /^\$\((.*?)\)(?: ?\/ ?(.+?))?$/.exec(variableDefinition);
409
- const flatName = name.join('-');
351
+ name: '-' + variable.name,
352
+ key: '-' + variable.key,
353
+ value: variable.value * -1
354
+ }, mode);
355
+ } else if (typeof variable.value === 'string') {
356
+ const aliasResult = /^\$\((.*?)\)(?: ?\/ ?(.+?))?$|^\$([a-zA-Z0-9-]+)(?: ?\/ ?(.+?))?$/.exec(variable.value);
410
357
  if (aliasResult) {
411
- let aliasVariableModeResolver = aliasVariableModeResolvers.get(flatName);
358
+ const alias = aliasResult[1] ?? aliasResult[3];
359
+ const alpha = aliasResult[2] ?? aliasResult[4];
360
+ let aliasVariableModeResolver = aliasVariableModeResolvers.get(variable.name);
412
361
  if (!aliasVariableModeResolver) {
413
- aliasVariableModeResolvers.set(flatName, aliasVariableModeResolver = {});
362
+ aliasVariableModeResolvers.set(variable.name, aliasVariableModeResolver = {});
414
363
  }
415
364
  aliasVariableModeResolver[mode] = ()=>{
416
365
  delete aliasVariableModeResolver[mode];
417
- const [alias, aliasMode] = aliasResult[1].split('@');
418
- if (alias) {
419
- const eachAliasModeVariableResolver = aliasVariableModeResolvers.get(alias);
420
- if (eachAliasModeVariableResolver) {
421
- for (const mode of Object.keys(eachAliasModeVariableResolver)){
422
- eachAliasModeVariableResolver[mode]?.();
366
+ if (!alias) return;
367
+ const eachAliasModeVariableResolver = aliasVariableModeResolvers.get(alias);
368
+ if (eachAliasModeVariableResolver) {
369
+ for (const mode of Object.keys(eachAliasModeVariableResolver)){
370
+ eachAliasModeVariableResolver[mode]?.();
371
+ }
372
+ }
373
+ const aliasVariable = this.variables.get(alias);
374
+ if (aliasVariable) {
375
+ let resolvedAlpha;
376
+ if (alpha) {
377
+ const numberAlpha = Number(alpha) * (aliasVariable.alpha || 1);
378
+ if (numberAlpha < 1) resolvedAlpha = numberAlpha;
379
+ }
380
+ const newVariable = {
381
+ ...variable,
382
+ type: aliasVariable.type,
383
+ value: aliasVariable.value
384
+ };
385
+ if (aliasVariable.type === 'color') {
386
+ if (resolvedAlpha !== undefined) newVariable.alpha = resolvedAlpha;
387
+ if (aliasVariable.space) {
388
+ newVariable.space = aliasVariable.space;
423
389
  }
424
390
  }
425
- const aliasVariable = this.variables.get(alias);
426
- if (aliasVariable) {
427
- if (aliasMode === undefined && aliasVariable.modes) {
428
- addVariable(name, {
429
- type: aliasVariable.type,
430
- value: aliasVariable.value,
431
- space: aliasVariable.space
432
- }, '', aliasResult[2]);
433
- for(const mode in aliasVariable.modes){
434
- addVariable(name, aliasVariable.modes[mode], mode, aliasResult[2]);
435
- }
436
- } else {
437
- const variable = aliasMode !== undefined ? aliasVariable.modes?.[aliasMode] : aliasVariable;
438
- if (variable) {
439
- const newVariable = {
440
- type: variable.type,
441
- value: variable.value
442
- };
443
- if (variable.type === 'color') {
444
- newVariable.space = variable.space;
445
- }
446
- addVariable(name, newVariable, undefined, aliasResult[2]);
447
- }
391
+ addVariable(newVariable.name, newVariable, mode);
392
+ if (aliasVariable.modes) {
393
+ for(const eachMode in aliasVariable.modes){
394
+ const aliasModeVariable = aliasVariable.modes[eachMode];
395
+ addVariable(newVariable.name, aliasModeVariable, eachMode);
448
396
  }
449
397
  }
450
398
  }
451
399
  };
452
400
  } else {
453
- const hexColorResult = /^#([A-Fa-f0-9]{3,4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.exec(variableDefinition);
454
- if (hexColorResult) {
455
- const [r, g, b, a] = hexToRgb(hexColorResult[1]);
456
- addVariable(name, {
401
+ // 1. HEX
402
+ const hexMatch = /^#([a-f0-9]{3,4}|[a-f0-9]{6}|[a-f0-9]{8})$/i.exec(variable.value);
403
+ if (hexMatch) {
404
+ const [r, g, b, a] = hexToRgb(hexMatch[1]);
405
+ const newVariable = {
406
+ ...variable,
457
407
  type: 'color',
458
- value: `${r} ${g} ${b}${a === 1 ? '' : ' / ' + a}`,
408
+ value: `${r} ${g} ${b}`,
459
409
  space: 'rgb'
460
- });
461
- } else {
462
- const rgbFunctionResult = /^rgb\( *([0-9]{1,3})(?: *, *| +)([0-9]{1,3})(?: *, *| +)([0-9]{1,3}) *(?:(?:,|\/) *(.*?) *)?\)$/.exec(variableDefinition);
463
- if (rgbFunctionResult) {
464
- addVariable(name, {
465
- type: 'color',
466
- value: rgbFunctionResult[1] + ' ' + rgbFunctionResult[2] + ' ' + rgbFunctionResult[3] + (rgbFunctionResult[4] ? ' / ' + (rgbFunctionResult[4].startsWith('0.') ? rgbFunctionResult[4].slice(1) : rgbFunctionResult[4]) : ''),
467
- space: 'rgb'
468
- });
469
- } else {
470
- const hslFunctionResult = /^hsl\((.*?)\)$/.exec(variableDefinition);
471
- if (hslFunctionResult) {
472
- addVariable(name, {
473
- type: 'color',
474
- value: hslFunctionResult[1],
475
- space: 'hsl'
476
- });
477
- } else {
478
- addVariable(name, {
479
- type: 'string',
480
- value: variableDefinition
481
- });
482
- }
410
+ };
411
+ if (a !== undefined && a < 1) {
412
+ newVariable.alpha = a;
483
413
  }
414
+ addVariable(newVariable.name, newVariable, mode);
415
+ return;
484
416
  }
417
+ // 2. COLOR FUNCTION
418
+ const funcMatch = /^(color|color-contrast|color-mix|hwb|lab|lch|oklab|oklch|rgb|hsl|light-dark)\((.+)\)$/i.exec(variable.value);
419
+ if (funcMatch) {
420
+ let [, space, rawArgs] = funcMatch;
421
+ space = space.toLowerCase();
422
+ const normalizedArgs = rawArgs.replace(/\s*\/\s*/g, '/').replace(/\s*,\s*/g, ' ').replace(/\s+/g, ' ').trim();
423
+ let alpha;
424
+ const alphaMatch = /^(.+?)\/([^\s]+)$/.exec(normalizedArgs);
425
+ const finalArgs = alphaMatch ? alphaMatch[1].trim() : normalizedArgs;
426
+ alpha = alphaMatch ? Number(alphaMatch[2]) : undefined;
427
+ const newVariable = {
428
+ ...variable,
429
+ type: 'color',
430
+ value: finalArgs,
431
+ space
432
+ };
433
+ if (alpha !== undefined) {
434
+ newVariable.alpha = alpha;
435
+ }
436
+ addVariable(newVariable.name, newVariable, mode);
437
+ return;
438
+ }
439
+ // 3. Fallback
440
+ addVariable(variable.name, {
441
+ ...variable,
442
+ type: 'string'
443
+ }, mode);
485
444
  }
486
445
  }
487
446
  };
488
447
  if (variables) {
489
448
  for(const parnetKey in variables){
490
- resolveVariable(variables[parnetKey], [
491
- parnetKey
492
- ]);
449
+ const variable = variables[parnetKey];
450
+ resolveVariable(variable);
493
451
  }
494
- // todo: address to the target variable
495
- aliasVariableModeResolvers.forEach((aliasVariableModeResolver)=>{
496
- for (const mode of Object.keys(aliasVariableModeResolver)){
497
- aliasVariableModeResolver[mode]?.();
452
+ }
453
+ if (modes) {
454
+ for(const mode in modes){
455
+ const modeVariables = modes[mode];
456
+ if (!modeVariables) continue;
457
+ for(const key in modeVariables){
458
+ const variable = modeVariables[key];
459
+ resolveVariable(variable, mode);
498
460
  }
499
- });
461
+ }
500
462
  }
463
+ // todo: address to the target variable
464
+ aliasVariableModeResolvers.forEach((aliasVariableModeResolver)=>{
465
+ for (const mode of Object.keys(aliasVariableModeResolver)){
466
+ aliasVariableModeResolver[mode]?.();
467
+ }
468
+ });
501
469
  if (screens) {
502
- resolveVariable(screens, [
503
- 'screen'
504
- ]);
470
+ for(const key in screens){
471
+ const value = screens[key];
472
+ const name = 'screen-' + key;
473
+ this.variables.set(name, {
474
+ name,
475
+ key,
476
+ namespace: 'screen',
477
+ group: 'screen',
478
+ type: 'number',
479
+ value
480
+ });
481
+ this.variables.set('-' + name, {
482
+ name: '-' + name,
483
+ key: '-' + key,
484
+ namespace: 'screen',
485
+ group: 'screen',
486
+ type: 'number',
487
+ value: value * -1
488
+ });
489
+ }
505
490
  }
506
491
  }
507
492
  parseValue(token, unit = 'rem') {
@@ -520,7 +505,7 @@ class MasterCSS {
520
505
  }
521
506
  /**
522
507
  * 2. value (ambiguous.key * ambiguous.values)
523
- * @example bg:current box:content font:12
508
+ * @example bg:current box-content font:12
524
509
  */ for (const eachSyntax of this.definedRules){
525
510
  if (eachSyntax.matchers.value?.test(className)) return eachSyntax;
526
511
  }
@@ -550,7 +535,7 @@ class MasterCSS {
550
535
  if (syntaxRule && syntaxRule.valid) {
551
536
  syntaxRules.push(syntaxRule);
552
537
  } else {
553
- console.error(`Invalid syntax class "${cls}" is in ${className} component.`);
538
+ console.error(`Invalid class "${cls}" found in ${className} component.`);
554
539
  }
555
540
  });
556
541
  } else {
@@ -674,14 +659,11 @@ class MasterCSS {
674
659
  }
675
660
  }
676
661
  getModeSelector(modeName) {
677
- const mode = this.config.modes?.[modeName];
678
- if (mode) {
679
- switch(mode){
680
- case 'class':
681
- return '.' + modeName;
682
- case 'host':
683
- return ':host(.' + modeName + ')';
684
- }
662
+ switch(this.config.modeTrigger){
663
+ case 'class':
664
+ return '.' + modeName;
665
+ case 'host':
666
+ return ':host(.' + modeName + ')';
685
667
  }
686
668
  }
687
669
  }