@master/css 2.0.0-rc.68 → 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 +234 -234
- package/dist/core.d.ts +5 -3
- package/dist/core.mjs +234 -234
- 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 -258
- package/dist/syntax-rule.d.ts +2 -2
- package/dist/syntax-rule.mjs +306 -259
- 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/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 +2 -4
- package/dist/utils/parse-selector.d.ts +2 -2
- package/dist/utils/parse-selector.mjs +2 -4
- 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){
|
|
@@ -253,9 +266,8 @@ class MasterCSS {
|
|
|
253
266
|
resolveSelectors() {
|
|
254
267
|
const { selectors } = this.config;
|
|
255
268
|
if (selectors) {
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
const value = flatSelectors[token];
|
|
269
|
+
for(const token in selectors){
|
|
270
|
+
const value = selectors[token];
|
|
259
271
|
const nodes = parseSelector(value, this, false);
|
|
260
272
|
this.selectors.set(token, nodes);
|
|
261
273
|
}
|
|
@@ -276,9 +288,8 @@ class MasterCSS {
|
|
|
276
288
|
}
|
|
277
289
|
}
|
|
278
290
|
if (at) {
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
const value = flatAt[token];
|
|
291
|
+
for(const token in at){
|
|
292
|
+
const value = at[token];
|
|
282
293
|
if (typeof value === 'number') {
|
|
283
294
|
const node = this.parseValue(value);
|
|
284
295
|
this.atRules.set(token, {
|
|
@@ -295,195 +306,187 @@ class MasterCSS {
|
|
|
295
306
|
}
|
|
296
307
|
}
|
|
297
308
|
resolveVariables() {
|
|
298
|
-
const { variables, screens } = this.config;
|
|
309
|
+
const { variables, screens, modes } = this.config;
|
|
299
310
|
const aliasVariableModeResolvers = new Map();
|
|
300
|
-
const resolveVariable = (
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
if (groups.length) variable.group = groups.join('.');
|
|
310
|
-
if (variable.type === 'color') {
|
|
311
|
-
if (alpha) {
|
|
312
|
-
const slashIndex = variable.value.indexOf('/');
|
|
313
|
-
variable = {
|
|
314
|
-
...variable,
|
|
315
|
-
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)
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
const currentMode = replacedMode ?? mode;
|
|
320
|
-
if (currentMode !== undefined) {
|
|
321
|
-
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;
|
|
322
320
|
if (foundVariable) {
|
|
323
|
-
if (
|
|
324
|
-
|
|
325
|
-
foundVariable.modes = {};
|
|
326
|
-
}
|
|
327
|
-
foundVariable.modes[currentMode] = variable;
|
|
328
|
-
} else {
|
|
329
|
-
foundVariable.value = variable.value;
|
|
330
|
-
if (variable.type === 'color') {
|
|
331
|
-
foundVariable.space = variable.space;
|
|
332
|
-
}
|
|
321
|
+
if (newVariable.type && newVariable.type !== foundVariable.type) {
|
|
322
|
+
return;
|
|
333
323
|
}
|
|
324
|
+
if (!foundVariable.modes) foundVariable.modes = {};
|
|
325
|
+
foundVariable.modes[currentMode] = newModeVariable;
|
|
334
326
|
} else {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
modes: {
|
|
342
|
-
[currentMode]: variable
|
|
343
|
-
}
|
|
344
|
-
};
|
|
345
|
-
if (variable.type === 'color') {
|
|
346
|
-
newVariable.space = variable.space;
|
|
327
|
+
const newRootVaraible = {
|
|
328
|
+
name: newVariable.name,
|
|
329
|
+
key: newVariable.key,
|
|
330
|
+
type: newVariable.type,
|
|
331
|
+
modes: {
|
|
332
|
+
[currentMode]: newModeVariable
|
|
347
333
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
334
|
+
};
|
|
335
|
+
if (newVariable.namespace) newRootVaraible.namespace = newVariable.namespace;
|
|
336
|
+
if (newVariable.group) newRootVaraible.group = newVariable.group;
|
|
337
|
+
this.variables.set(name, newRootVaraible);
|
|
352
338
|
}
|
|
353
339
|
} else {
|
|
354
|
-
this.variables.set(
|
|
340
|
+
this.variables.set(name, newVariable);
|
|
355
341
|
}
|
|
356
342
|
};
|
|
357
|
-
if (typeof
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
const keys = Object.keys(variableDefinition);
|
|
365
|
-
for (const eachKey of keys){
|
|
366
|
-
if (eachKey === '' || eachKey.startsWith('@')) {
|
|
367
|
-
resolveVariable(variableDefinition[eachKey], name, eachKey || keys.some((eachKey)=>eachKey.startsWith('@')) ? eachKey.slice(1) : undefined);
|
|
368
|
-
} else {
|
|
369
|
-
resolveVariable(variableDefinition[eachKey], [
|
|
370
|
-
...name,
|
|
371
|
-
eachKey
|
|
372
|
-
]);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
} else if (typeof variableDefinition === 'number') {
|
|
377
|
-
addVariable(name, {
|
|
343
|
+
if (typeof variable.value === 'number') {
|
|
344
|
+
addVariable(variable.name, {
|
|
345
|
+
...variable,
|
|
346
|
+
type: 'number'
|
|
347
|
+
}, mode);
|
|
348
|
+
addVariable('-' + variable.name, {
|
|
349
|
+
...variable,
|
|
378
350
|
type: 'number',
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
]
|
|
385
|
-
type: 'number',
|
|
386
|
-
value: variableDefinition * -1
|
|
387
|
-
});
|
|
388
|
-
} else if (typeof variableDefinition === 'string') {
|
|
389
|
-
const aliasResult = /^\$\((.*?)\)(?: ?\/ ?(.+?))?$|^\$([a-zA-Z0-9-]+)(?: ?\/ ?(.+?))?$/.exec(variableDefinition);
|
|
390
|
-
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);
|
|
391
357
|
if (aliasResult) {
|
|
392
358
|
const alias = aliasResult[1] ?? aliasResult[3];
|
|
393
|
-
const
|
|
394
|
-
let aliasVariableModeResolver = aliasVariableModeResolvers.get(
|
|
359
|
+
const alpha = aliasResult[2] ?? aliasResult[4];
|
|
360
|
+
let aliasVariableModeResolver = aliasVariableModeResolvers.get(variable.name);
|
|
395
361
|
if (!aliasVariableModeResolver) {
|
|
396
|
-
aliasVariableModeResolvers.set(
|
|
362
|
+
aliasVariableModeResolvers.set(variable.name, aliasVariableModeResolver = {});
|
|
397
363
|
}
|
|
398
364
|
aliasVariableModeResolver[mode] = ()=>{
|
|
399
365
|
delete aliasVariableModeResolver[mode];
|
|
400
366
|
if (!alias) return;
|
|
401
|
-
const
|
|
402
|
-
const eachAliasModeVariableResolver = aliasVariableModeResolvers.get(baseAlias);
|
|
367
|
+
const eachAliasModeVariableResolver = aliasVariableModeResolvers.get(alias);
|
|
403
368
|
if (eachAliasModeVariableResolver) {
|
|
404
369
|
for (const mode of Object.keys(eachAliasModeVariableResolver)){
|
|
405
370
|
eachAliasModeVariableResolver[mode]?.();
|
|
406
371
|
}
|
|
407
372
|
}
|
|
408
|
-
const aliasVariable = this.variables.get(
|
|
373
|
+
const aliasVariable = this.variables.get(alias);
|
|
409
374
|
if (aliasVariable) {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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;
|
|
418
389
|
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
...variable.type === 'color' ? {
|
|
426
|
-
space: variable.space
|
|
427
|
-
} : {}
|
|
428
|
-
};
|
|
429
|
-
addVariable(name, newVariable, undefined, modeSuffix);
|
|
390
|
+
}
|
|
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);
|
|
430
396
|
}
|
|
431
397
|
}
|
|
432
398
|
}
|
|
433
399
|
};
|
|
434
400
|
} else {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
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,
|
|
439
407
|
type: 'color',
|
|
440
|
-
value: `${r} ${g} ${b}
|
|
408
|
+
value: `${r} ${g} ${b}`,
|
|
441
409
|
space: 'rgb'
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
410
|
+
};
|
|
411
|
+
if (a !== undefined && a < 1) {
|
|
412
|
+
newVariable.alpha = a;
|
|
413
|
+
}
|
|
414
|
+
addVariable(newVariable.name, newVariable, mode);
|
|
415
|
+
return;
|
|
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;
|
|
465
435
|
}
|
|
436
|
+
addVariable(newVariable.name, newVariable, mode);
|
|
437
|
+
return;
|
|
466
438
|
}
|
|
439
|
+
// 3. Fallback
|
|
440
|
+
addVariable(variable.name, {
|
|
441
|
+
...variable,
|
|
442
|
+
type: 'string'
|
|
443
|
+
}, mode);
|
|
467
444
|
}
|
|
468
445
|
}
|
|
469
446
|
};
|
|
470
447
|
if (variables) {
|
|
471
448
|
for(const parnetKey in variables){
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
]);
|
|
449
|
+
const variable = variables[parnetKey];
|
|
450
|
+
resolveVariable(variable);
|
|
475
451
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
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);
|
|
480
460
|
}
|
|
481
|
-
}
|
|
461
|
+
}
|
|
482
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
|
+
});
|
|
483
469
|
if (screens) {
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
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
|
+
}
|
|
487
490
|
}
|
|
488
491
|
}
|
|
489
492
|
parseValue(token, unit = 'rem') {
|
|
@@ -502,7 +505,7 @@ class MasterCSS {
|
|
|
502
505
|
}
|
|
503
506
|
/**
|
|
504
507
|
* 2. value (ambiguous.key * ambiguous.values)
|
|
505
|
-
* @example bg:current box
|
|
508
|
+
* @example bg:current box-content font:12
|
|
506
509
|
*/ for (const eachSyntax of this.definedRules){
|
|
507
510
|
if (eachSyntax.matchers.value?.test(className)) return eachSyntax;
|
|
508
511
|
}
|
|
@@ -656,14 +659,11 @@ class MasterCSS {
|
|
|
656
659
|
}
|
|
657
660
|
}
|
|
658
661
|
getModeSelector(modeName) {
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
case 'host':
|
|
665
|
-
return ':host(.' + modeName + ')';
|
|
666
|
-
}
|
|
662
|
+
switch(this.config.modeTrigger){
|
|
663
|
+
case 'class':
|
|
664
|
+
return '.' + modeName;
|
|
665
|
+
case 'host':
|
|
666
|
+
return ':host(.' + modeName + ')';
|
|
667
667
|
}
|
|
668
668
|
}
|
|
669
669
|
}
|
package/dist/core.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SyntaxRule } from './syntax-rule';
|
|
2
|
+
import { ExtendedConfig } from './utils/extend-config';
|
|
2
3
|
import { Rule } from './rule';
|
|
3
4
|
import Layer from './layer';
|
|
4
5
|
import NonLayer from './non-layer';
|
|
@@ -8,9 +9,9 @@ import { AnimationDefinitions, Config } from './types/config';
|
|
|
8
9
|
import { SelectorNode } from './utils/parse-selector';
|
|
9
10
|
export default class MasterCSS {
|
|
10
11
|
customConfig?: Config | undefined;
|
|
11
|
-
|
|
12
|
+
baseConfig?: Config | undefined;
|
|
12
13
|
readonly definedRules: DefinedRule[];
|
|
13
|
-
readonly config:
|
|
14
|
+
readonly config: ExtendedConfig;
|
|
14
15
|
readonly layerStatementRule: Rule;
|
|
15
16
|
readonly rules: (Layer | Rule)[];
|
|
16
17
|
readonly classRules: Map<string, SyntaxRule[]>;
|
|
@@ -75,9 +76,10 @@ export default class MasterCSS {
|
|
|
75
76
|
readonly components: Map<string, string[]>;
|
|
76
77
|
readonly selectors: Map<string, SelectorNode[]>;
|
|
77
78
|
readonly variables: Map<string, Variable>;
|
|
79
|
+
readonly modes: string[];
|
|
78
80
|
readonly atRules: Map<string, AtRule>;
|
|
79
81
|
readonly animations: Map<string, AnimationDefinitions>;
|
|
80
|
-
constructor(customConfig?: Config | undefined);
|
|
82
|
+
constructor(customConfig?: Config | undefined, baseConfig?: Config | undefined);
|
|
81
83
|
get text(): string;
|
|
82
84
|
resolve(customConfig?: Config): void;
|
|
83
85
|
resolveAnimations(): void;
|