@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.
- package/dist/common.cjs +0 -2
- package/dist/common.d.ts +0 -1
- package/dist/common.mjs +1 -2
- package/dist/config/functions.cjs +9 -243
- package/dist/config/functions.d.ts +137 -2
- package/dist/config/functions.mjs +9 -243
- package/dist/config/index.cjs +2 -2
- package/dist/config/index.mjs +2 -2
- package/dist/config/modes.cjs +307 -3
- package/dist/config/modes.d.ts +306 -2
- package/dist/config/modes.mjs +307 -3
- package/dist/config/rules.cjs +740 -782
- package/dist/config/rules.d.ts +692 -683
- package/dist/config/rules.mjs +741 -783
- package/dist/config/utilities.cjs +328 -97
- package/dist/config/utilities.d.ts +247 -16
- package/dist/config/utilities.mjs +328 -97
- package/dist/config/variables.cjs +88 -460
- package/dist/config/variables.d.ts +358 -369
- package/dist/config/variables.mjs +88 -460
- package/dist/core.cjs +242 -260
- package/dist/core.d.ts +5 -3
- package/dist/core.mjs +242 -260
- package/dist/create.cjs +10 -0
- package/dist/create.d.ts +3 -0
- package/dist/create.mjs +8 -0
- package/dist/declarers/core.group.cjs +99 -0
- package/dist/declarers/core.group.d.ts +2 -0
- package/dist/declarers/core.group.mjs +97 -0
- package/dist/declarers/core.variable.cjs +9 -0
- package/dist/declarers/core.variable.d.ts +4 -0
- package/dist/declarers/core.variable.mjs +7 -0
- package/dist/declarers/index.cjs +13 -0
- package/dist/declarers/index.d.ts +10 -0
- package/dist/declarers/index.mjs +11 -0
- package/dist/declarers/pair.cjs +12 -0
- package/dist/declarers/pair.d.ts +4 -0
- package/dist/declarers/pair.mjs +10 -0
- package/dist/factories/with-syntax-layer.cjs +0 -2
- package/dist/factories/with-syntax-layer.mjs +0 -2
- package/dist/function-transformers/core.calc.cjs +225 -0
- package/dist/function-transformers/core.calc.d.ts +2 -0
- package/dist/function-transformers/core.calc.mjs +223 -0
- package/dist/function-transformers/core.variable.cjs +23 -0
- package/dist/function-transformers/core.variable.d.ts +7 -0
- package/dist/function-transformers/core.variable.mjs +21 -0
- package/dist/function-transformers/index.cjs +11 -0
- package/dist/function-transformers/index.d.ts +8 -0
- package/dist/function-transformers/index.mjs +9 -0
- package/dist/index.cjs +10 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.mjs +6 -1
- package/dist/layer.cjs +2 -4
- package/dist/layer.mjs +2 -4
- package/dist/non-layer.cjs +2 -4
- package/dist/non-layer.mjs +2 -4
- package/dist/syntax-rule-type.cjs +8 -7
- package/dist/syntax-rule-type.d.ts +7 -7
- package/dist/syntax-rule-type.mjs +8 -7
- package/dist/syntax-rule.cjs +305 -253
- package/dist/syntax-rule.d.ts +2 -2
- package/dist/syntax-rule.mjs +306 -254
- package/dist/{utils/autofill-solid-style.cjs → transformers/auto-fill-solid.cjs} +3 -3
- package/dist/transformers/auto-fill-solid.d.ts +2 -0
- package/dist/{utils/autofill-solid-style.mjs → transformers/auto-fill-solid.mjs} +3 -3
- package/dist/transformers/index.cjs +9 -0
- package/dist/transformers/index.d.ts +6 -0
- package/dist/transformers/index.mjs +7 -0
- package/dist/types/common.d.ts +0 -2
- package/dist/types/config.d.ts +24 -20
- package/dist/types/syntax.d.ts +10 -8
- package/dist/utils/equal-selectors.cjs +1 -2
- package/dist/utils/equal-selectors.mjs +1 -2
- package/dist/utils/extend-config.cjs +83 -44
- package/dist/utils/extend-config.d.ts +10 -1
- package/dist/utils/extend-config.mjs +83 -44
- package/dist/utils/flatten-meta-object.cjs +38 -0
- package/dist/utils/flatten-meta-object.d.ts +13 -0
- package/dist/utils/flatten-meta-object.mjs +36 -0
- package/dist/utils/flatten-object.cjs +13 -9
- package/dist/utils/flatten-object.d.ts +1 -1
- package/dist/utils/flatten-object.mjs +13 -9
- package/dist/utils/generate-css.cjs +2 -2
- package/dist/utils/generate-css.d.ts +1 -2
- package/dist/utils/generate-css.mjs +2 -2
- package/dist/utils/generate-selector.cjs +2 -1
- package/dist/utils/generate-selector.mjs +2 -1
- package/dist/utils/minify-extended-config.cjs +64 -0
- package/dist/utils/minify-extended-config.d.ts +9 -0
- package/dist/utils/minify-extended-config.mjs +62 -0
- package/dist/utils/nest-meta-object.cjs +25 -0
- package/dist/utils/nest-meta-object.d.ts +7 -0
- package/dist/utils/nest-meta-object.mjs +23 -0
- package/dist/utils/parse-at.cjs +1 -2
- package/dist/utils/parse-at.d.ts +2 -2
- package/dist/utils/parse-at.mjs +1 -2
- package/dist/utils/parse-pair.cjs +3 -6
- package/dist/utils/parse-pair.mjs +3 -6
- package/dist/utils/parse-selector.cjs +6 -6
- package/dist/utils/parse-selector.d.ts +3 -3
- package/dist/utils/parse-selector.mjs +6 -6
- package/dist/utils/sort-readable-classes.cjs +2 -2
- package/dist/utils/sort-readable-classes.d.ts +1 -2
- package/dist/utils/sort-readable-classes.mjs +2 -2
- package/dist/variable-rule.cjs +35 -29
- package/dist/variable-rule.d.ts +16 -6
- package/dist/variable-rule.mjs +35 -29
- package/package.json +1 -1
- 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
|
-
|
|
21
|
-
definedRules;
|
|
18
|
+
baseConfig;
|
|
19
|
+
definedRules = [];
|
|
22
20
|
config;
|
|
23
|
-
layerStatementRule;
|
|
24
|
-
rules
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
components;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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.
|
|
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 =
|
|
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
|
-
|
|
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
|
|
155
|
+
const addNamespace = (namespace)=>{
|
|
156
|
+
const dashedNamespace = namespace.replace(/\./g, '-');
|
|
170
157
|
this.variables.forEach((v)=>{
|
|
171
|
-
if (v.group ===
|
|
172
|
-
|
|
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
|
-
//
|
|
177
|
-
|
|
178
|
-
|
|
176
|
+
// 1. Auto variable binding
|
|
177
|
+
addNamespace(id);
|
|
178
|
+
// 2. Rule-defined variable groups
|
|
179
|
+
if (namespaces) {
|
|
180
|
+
namespaces.forEach(addNamespace);
|
|
179
181
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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 (
|
|
199
|
-
const keyPattern =
|
|
200
|
-
const variableKeys =
|
|
201
|
-
|
|
202
|
-
|
|
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
|
|
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 =
|
|
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
|
|
276
|
-
|
|
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
|
|
299
|
-
|
|
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 = (
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
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 (
|
|
343
|
-
|
|
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
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
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
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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(
|
|
340
|
+
this.variables.set(name, newVariable);
|
|
374
341
|
}
|
|
375
342
|
};
|
|
376
|
-
if (typeof
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
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
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
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
|
-
|
|
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(
|
|
362
|
+
aliasVariableModeResolvers.set(variable.name, aliasVariableModeResolver = {});
|
|
414
363
|
}
|
|
415
364
|
aliasVariableModeResolver[mode] = ()=>{
|
|
416
365
|
delete aliasVariableModeResolver[mode];
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
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
|
-
|
|
426
|
-
if (aliasVariable) {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
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
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
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}
|
|
408
|
+
value: `${r} ${g} ${b}`,
|
|
459
409
|
space: 'rgb'
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
|
|
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
|
-
|
|
491
|
-
|
|
492
|
-
]);
|
|
449
|
+
const variable = variables[parnetKey];
|
|
450
|
+
resolveVariable(variable);
|
|
493
451
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
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
|
-
|
|
503
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
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
|
}
|