@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.mjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { SyntaxRule } from './syntax-rule.mjs';
|
|
2
|
-
import { config } from './config/index.mjs';
|
|
3
2
|
import hexToRgb from './utils/hex-to-rgb.mjs';
|
|
4
|
-
import { flattenObject } from './utils/flatten-object.mjs';
|
|
5
3
|
import extendConfig from './utils/extend-config.mjs';
|
|
6
4
|
import { Rule } from './rule.mjs';
|
|
7
5
|
import SyntaxRuleType from './syntax-rule-type.mjs';
|
|
@@ -15,42 +13,29 @@ import parseSelector from './utils/parse-selector.mjs';
|
|
|
15
13
|
|
|
16
14
|
class MasterCSS {
|
|
17
15
|
customConfig;
|
|
18
|
-
|
|
19
|
-
definedRules;
|
|
16
|
+
baseConfig;
|
|
17
|
+
definedRules = [];
|
|
20
18
|
config;
|
|
21
|
-
layerStatementRule;
|
|
22
|
-
rules
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
components;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
19
|
+
layerStatementRule = new Rule('layer-statement', '@layer base,theme,preset,components,general;');
|
|
20
|
+
rules = [
|
|
21
|
+
this.layerStatementRule
|
|
22
|
+
];
|
|
23
|
+
classRules = new Map();
|
|
24
|
+
animationsNonLayer = new NonLayer(this);
|
|
25
|
+
baseLayer = new SyntaxLayer('base', this);
|
|
26
|
+
themeLayer = new Layer('theme', this);
|
|
27
|
+
presetLayer = new SyntaxLayer('preset', this);
|
|
28
|
+
componentsLayer = new SyntaxLayer('components', this);
|
|
29
|
+
generalLayer = new SyntaxLayer('general', this);
|
|
30
|
+
components = new Map();
|
|
31
|
+
selectors = new Map();
|
|
32
|
+
variables = new Map();
|
|
33
|
+
modes = [];
|
|
34
|
+
atRules = new Map();
|
|
35
|
+
animations = new Map();
|
|
36
|
+
constructor(customConfig, baseConfig){
|
|
36
37
|
this.customConfig = customConfig;
|
|
37
|
-
this.
|
|
38
|
-
this.layerStatementRule = new Rule('layer-statement', '@layer base,theme,preset,components,general;');
|
|
39
|
-
this.rules = [
|
|
40
|
-
this.layerStatementRule
|
|
41
|
-
];
|
|
42
|
-
this.classRules = new Map();
|
|
43
|
-
this.animationsNonLayer = new NonLayer(this);
|
|
44
|
-
this.baseLayer = new SyntaxLayer('base', this);
|
|
45
|
-
this.themeLayer = new Layer('theme', this);
|
|
46
|
-
this.presetLayer = new SyntaxLayer('preset', this);
|
|
47
|
-
this.componentsLayer = new SyntaxLayer('components', this);
|
|
48
|
-
this.generalLayer = new SyntaxLayer('general', this);
|
|
49
|
-
this.components = new Map();
|
|
50
|
-
this.selectors = new Map();
|
|
51
|
-
this.variables = new Map();
|
|
52
|
-
this.atRules = new Map();
|
|
53
|
-
this.animations = new Map();
|
|
38
|
+
this.baseConfig = baseConfig;
|
|
54
39
|
this.resolve(customConfig);
|
|
55
40
|
}
|
|
56
41
|
get text() {
|
|
@@ -75,7 +60,7 @@ class MasterCSS {
|
|
|
75
60
|
customConfig = this.customConfig;
|
|
76
61
|
}
|
|
77
62
|
// @ts-expect-error read-only
|
|
78
|
-
this.config =
|
|
63
|
+
this.config = this.baseConfig ? extendConfig(this.baseConfig, customConfig) : extendConfig(customConfig);
|
|
79
64
|
this.resolveVariables();
|
|
80
65
|
this.resolveAnimations();
|
|
81
66
|
this.resolveSelectors();
|
|
@@ -125,23 +110,25 @@ class MasterCSS {
|
|
|
125
110
|
rulesEntries.push(...Object.entries(rules));
|
|
126
111
|
}
|
|
127
112
|
const rulesEntriesLength = rulesEntries.length;
|
|
128
|
-
// Prepare color variables
|
|
129
|
-
const colorNames = new Set([
|
|
130
|
-
'current',
|
|
131
|
-
'currentColor',
|
|
132
|
-
'transparent'
|
|
133
|
-
]);
|
|
134
|
-
this.variables.forEach((v)=>{
|
|
135
|
-
if (v.type === 'color') colorNames.add(v.name);
|
|
136
|
-
});
|
|
137
|
-
const colorPattern = [
|
|
138
|
-
...colorNames
|
|
139
|
-
].join('|');
|
|
140
113
|
// Main loop
|
|
141
114
|
rulesEntries.sort((a, b)=>{
|
|
142
115
|
if (a[1].type !== b[1].type) {
|
|
143
116
|
return (b[1].type || 0) - (a[1].type || 0);
|
|
144
117
|
}
|
|
118
|
+
if (a[1].kind !== b[1].kind) {
|
|
119
|
+
if (!a[1].kind) return 1;
|
|
120
|
+
if (!b[1].kind) return -1;
|
|
121
|
+
const kindOrder = [
|
|
122
|
+
'color',
|
|
123
|
+
'number',
|
|
124
|
+
'image'
|
|
125
|
+
];
|
|
126
|
+
const aKindIndex = kindOrder.indexOf(a[1].kind);
|
|
127
|
+
const bKindIndex = kindOrder.indexOf(b[1].kind);
|
|
128
|
+
if (aKindIndex !== bKindIndex) {
|
|
129
|
+
return aKindIndex - bKindIndex;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
145
132
|
return b[0].localeCompare(a[0], undefined, {
|
|
146
133
|
numeric: true
|
|
147
134
|
});
|
|
@@ -150,7 +137,6 @@ class MasterCSS {
|
|
|
150
137
|
const syntax = {
|
|
151
138
|
id,
|
|
152
139
|
keys: [],
|
|
153
|
-
variables: {},
|
|
154
140
|
matchers: {},
|
|
155
141
|
order,
|
|
156
142
|
definition: def
|
|
@@ -160,25 +146,42 @@ class MasterCSS {
|
|
|
160
146
|
','
|
|
161
147
|
];
|
|
162
148
|
this.definedRules.push(syntax);
|
|
163
|
-
|
|
149
|
+
let { matcher, type, subkey, aliasGroups, values, kind, sign, key: originalKey, namespaces } = def;
|
|
164
150
|
const keys = [];
|
|
165
151
|
let key = originalKey;
|
|
166
152
|
// Helper: resolve variable groups
|
|
167
|
-
const
|
|
153
|
+
const addNamespace = (namespace)=>{
|
|
154
|
+
const dashedNamespace = namespace.replace(/\./g, '-');
|
|
168
155
|
this.variables.forEach((v)=>{
|
|
169
|
-
if (v.group ===
|
|
170
|
-
|
|
156
|
+
if (v.namespace === namespace || v.group === namespace) {
|
|
157
|
+
let variableKey = v.name;
|
|
158
|
+
if (variableKey.startsWith('-' + dashedNamespace) || variableKey.startsWith(dashedNamespace)) {
|
|
159
|
+
variableKey = variableKey.slice(dashedNamespace.length + 1);
|
|
160
|
+
}
|
|
161
|
+
if (syntax.variables) {
|
|
162
|
+
syntax.variables.set(variableKey, v);
|
|
163
|
+
} else {
|
|
164
|
+
syntax.variables = new Map([
|
|
165
|
+
[
|
|
166
|
+
variableKey,
|
|
167
|
+
v
|
|
168
|
+
]
|
|
169
|
+
]);
|
|
170
|
+
}
|
|
171
171
|
}
|
|
172
172
|
});
|
|
173
173
|
};
|
|
174
|
-
//
|
|
175
|
-
|
|
176
|
-
|
|
174
|
+
// 1. Auto variable binding
|
|
175
|
+
addNamespace(id);
|
|
176
|
+
// 2. Rule-defined variable groups
|
|
177
|
+
if (namespaces) {
|
|
178
|
+
namespaces.forEach(addNamespace);
|
|
177
179
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
180
|
+
if (id.endsWith('()')) {
|
|
181
|
+
if (!key) def.key = key = id;
|
|
182
|
+
const fnName = id.slice(0, -2);
|
|
183
|
+
matcher = new RegExp(`^${fnName}\\(`);
|
|
184
|
+
} else if (type === SyntaxRuleType.NativeShorthand || type === SyntaxRuleType.Native) {
|
|
182
185
|
if (!key) def.key = key = id;
|
|
183
186
|
keys.push(id);
|
|
184
187
|
}
|
|
@@ -193,19 +196,30 @@ class MasterCSS {
|
|
|
193
196
|
if (type === SyntaxRuleType.Shorthand) keys.push(id);
|
|
194
197
|
}
|
|
195
198
|
// Ambiguous keys and values
|
|
196
|
-
if (
|
|
197
|
-
const keyPattern =
|
|
198
|
-
const variableKeys =
|
|
199
|
-
|
|
200
|
-
|
|
199
|
+
if (aliasGroups?.length) {
|
|
200
|
+
const keyPattern = aliasGroups.length > 1 ? `(?:${aliasGroups.join('|')})` : aliasGroups[0];
|
|
201
|
+
const variableKeys = Array.from(syntax.variables?.keys() || []);
|
|
202
|
+
const valuePatterns = values ? values.map((v)=>`${v}(?:\\b|_)`) : [];
|
|
203
|
+
switch(kind){
|
|
204
|
+
case 'color':
|
|
205
|
+
valuePatterns.push(`(?:#|(?:color|color-contrast|color-mix|hwb|lab|lch|oklab|oklch|rgb|rgba|hsl|hsla|light-dark)\\(.*\\)|(?:currentColor|transparent)(?![a-zA-Z0-9-]))`);
|
|
206
|
+
break;
|
|
207
|
+
case 'number':
|
|
208
|
+
valuePatterns.push('(?:[\\d.]|(?:max|min|calc|clamp)\\([^|]*\\))');
|
|
209
|
+
break;
|
|
210
|
+
case 'image':
|
|
211
|
+
valuePatterns.push('(?:url|linear-gradient|radial-gradient|repeating-linear-gradient|repeating-radial-gradient|conic-gradient)\\(.*\\)');
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
if (valuePatterns?.length) {
|
|
201
215
|
syntax.matchers.value = new RegExp(`^${keyPattern}:(?:${valuePatterns.join('|')})[^|]*?(?:@|$)`);
|
|
202
216
|
}
|
|
203
217
|
if (variableKeys.length) {
|
|
204
|
-
syntax.matchers.variable = new RegExp(`^${keyPattern}:(?:${variableKeys.join('|')}(?![a-zA-Z0-9-])
|
|
218
|
+
syntax.matchers.variable = new RegExp(`^${keyPattern}:(?:${variableKeys.join('|')})(?![a-zA-Z0-9-])[^|]*?(?:@|$)`);
|
|
205
219
|
}
|
|
206
220
|
}
|
|
207
221
|
} else {
|
|
208
|
-
syntax.matchers.arbitrary = matcher;
|
|
222
|
+
syntax.matchers.arbitrary = new RegExp(matcher);
|
|
209
223
|
}
|
|
210
224
|
// Utility rule matcher
|
|
211
225
|
if (type === SyntaxRuleType.Utility) {
|
|
@@ -220,16 +234,15 @@ class MasterCSS {
|
|
|
220
234
|
});
|
|
221
235
|
}
|
|
222
236
|
resolveComponents() {
|
|
223
|
-
const { components } = this.config;
|
|
224
|
-
const
|
|
225
|
-
const flatNames = Object.keys(flatComps);
|
|
237
|
+
const { components = {} } = this.config;
|
|
238
|
+
const flatNames = Object.keys(components);
|
|
226
239
|
const resolve = (name, currentClasses = [])=>{
|
|
227
240
|
const compClasses = this.components.get(name);
|
|
228
241
|
if (compClasses) {
|
|
229
242
|
currentClasses.push(...compClasses);
|
|
230
243
|
return;
|
|
231
244
|
}
|
|
232
|
-
const className =
|
|
245
|
+
const className = components[name];
|
|
233
246
|
if (!className) return;
|
|
234
247
|
const classes = className.replace(/(?:\n\s*)+/g, ' ').trim().split(' ');
|
|
235
248
|
for (const cls of classes){
|
|
@@ -251,9 +264,8 @@ class MasterCSS {
|
|
|
251
264
|
resolveSelectors() {
|
|
252
265
|
const { selectors } = this.config;
|
|
253
266
|
if (selectors) {
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
const value = flatSelectors[token];
|
|
267
|
+
for(const token in selectors){
|
|
268
|
+
const value = selectors[token];
|
|
257
269
|
const nodes = parseSelector(value, this, false);
|
|
258
270
|
this.selectors.set(token, nodes);
|
|
259
271
|
}
|
|
@@ -274,9 +286,8 @@ class MasterCSS {
|
|
|
274
286
|
}
|
|
275
287
|
}
|
|
276
288
|
if (at) {
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
const value = flatAt[token];
|
|
289
|
+
for(const token in at){
|
|
290
|
+
const value = at[token];
|
|
280
291
|
if (typeof value === 'number') {
|
|
281
292
|
const node = this.parseValue(value);
|
|
282
293
|
this.atRules.set(token, {
|
|
@@ -293,195 +304,187 @@ class MasterCSS {
|
|
|
293
304
|
}
|
|
294
305
|
}
|
|
295
306
|
resolveVariables() {
|
|
296
|
-
const { variables, screens } = this.config;
|
|
307
|
+
const { variables, screens, modes } = this.config;
|
|
297
308
|
const aliasVariableModeResolvers = new Map();
|
|
298
|
-
const resolveVariable = (
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
if (groups.length) variable.group = groups.join('.');
|
|
308
|
-
if (variable.type === 'color') {
|
|
309
|
-
if (alpha) {
|
|
310
|
-
const slashIndex = variable.value.indexOf('/');
|
|
311
|
-
variable = {
|
|
312
|
-
...variable,
|
|
313
|
-
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)
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
const currentMode = replacedMode ?? mode;
|
|
318
|
-
if (currentMode !== undefined) {
|
|
319
|
-
const foundVariable = this.variables.get(flatName);
|
|
309
|
+
const resolveVariable = (variable, mode)=>{
|
|
310
|
+
const addVariable = (name, newVariable, currentMode)=>{
|
|
311
|
+
if (currentMode) {
|
|
312
|
+
const foundVariable = this.variables.get(name);
|
|
313
|
+
const newModeVariable = {
|
|
314
|
+
value: newVariable.value
|
|
315
|
+
};
|
|
316
|
+
if ('alpha' in newVariable) newModeVariable.alpha = newVariable.alpha;
|
|
317
|
+
if ('space' in newVariable) newModeVariable.space = newVariable.space;
|
|
320
318
|
if (foundVariable) {
|
|
321
|
-
if (
|
|
322
|
-
|
|
323
|
-
foundVariable.modes = {};
|
|
324
|
-
}
|
|
325
|
-
foundVariable.modes[currentMode] = variable;
|
|
326
|
-
} else {
|
|
327
|
-
foundVariable.value = variable.value;
|
|
328
|
-
if (variable.type === 'color') {
|
|
329
|
-
foundVariable.space = variable.space;
|
|
330
|
-
}
|
|
319
|
+
if (newVariable.type && newVariable.type !== foundVariable.type) {
|
|
320
|
+
return;
|
|
331
321
|
}
|
|
322
|
+
if (!foundVariable.modes) foundVariable.modes = {};
|
|
323
|
+
foundVariable.modes[currentMode] = newModeVariable;
|
|
332
324
|
} else {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
modes: {
|
|
340
|
-
[currentMode]: variable
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
if (variable.type === 'color') {
|
|
344
|
-
newVariable.space = variable.space;
|
|
325
|
+
const newRootVaraible = {
|
|
326
|
+
name: newVariable.name,
|
|
327
|
+
key: newVariable.key,
|
|
328
|
+
type: newVariable.type,
|
|
329
|
+
modes: {
|
|
330
|
+
[currentMode]: newModeVariable
|
|
345
331
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
332
|
+
};
|
|
333
|
+
if (newVariable.namespace) newRootVaraible.namespace = newVariable.namespace;
|
|
334
|
+
if (newVariable.group) newRootVaraible.group = newVariable.group;
|
|
335
|
+
this.variables.set(name, newRootVaraible);
|
|
350
336
|
}
|
|
351
337
|
} else {
|
|
352
|
-
this.variables.set(
|
|
338
|
+
this.variables.set(name, newVariable);
|
|
353
339
|
}
|
|
354
340
|
};
|
|
355
|
-
if (typeof
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
const keys = Object.keys(variableDefinition);
|
|
363
|
-
for (const eachKey of keys){
|
|
364
|
-
if (eachKey === '' || eachKey.startsWith('@')) {
|
|
365
|
-
resolveVariable(variableDefinition[eachKey], name, eachKey || keys.some((eachKey)=>eachKey.startsWith('@')) ? eachKey.slice(1) : undefined);
|
|
366
|
-
} else {
|
|
367
|
-
resolveVariable(variableDefinition[eachKey], [
|
|
368
|
-
...name,
|
|
369
|
-
eachKey
|
|
370
|
-
]);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
} else if (typeof variableDefinition === 'number') {
|
|
375
|
-
addVariable(name, {
|
|
341
|
+
if (typeof variable.value === 'number') {
|
|
342
|
+
addVariable(variable.name, {
|
|
343
|
+
...variable,
|
|
344
|
+
type: 'number'
|
|
345
|
+
}, mode);
|
|
346
|
+
addVariable('-' + variable.name, {
|
|
347
|
+
...variable,
|
|
376
348
|
type: 'number',
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
]
|
|
383
|
-
type: 'number',
|
|
384
|
-
value: variableDefinition * -1
|
|
385
|
-
});
|
|
386
|
-
} else if (typeof variableDefinition === 'string') {
|
|
387
|
-
const aliasResult = /^\$\((.*?)\)(?: ?\/ ?(.+?))?$|^\$([a-zA-Z0-9-]+)(?: ?\/ ?(.+?))?$/.exec(variableDefinition);
|
|
388
|
-
const flatName = name.join('-');
|
|
349
|
+
name: '-' + variable.name,
|
|
350
|
+
key: '-' + variable.key,
|
|
351
|
+
value: variable.value * -1
|
|
352
|
+
}, mode);
|
|
353
|
+
} else if (typeof variable.value === 'string') {
|
|
354
|
+
const aliasResult = /^\$\((.*?)\)(?: ?\/ ?(.+?))?$|^\$([a-zA-Z0-9-]+)(?: ?\/ ?(.+?))?$/.exec(variable.value);
|
|
389
355
|
if (aliasResult) {
|
|
390
356
|
const alias = aliasResult[1] ?? aliasResult[3];
|
|
391
|
-
const
|
|
392
|
-
let aliasVariableModeResolver = aliasVariableModeResolvers.get(
|
|
357
|
+
const alpha = aliasResult[2] ?? aliasResult[4];
|
|
358
|
+
let aliasVariableModeResolver = aliasVariableModeResolvers.get(variable.name);
|
|
393
359
|
if (!aliasVariableModeResolver) {
|
|
394
|
-
aliasVariableModeResolvers.set(
|
|
360
|
+
aliasVariableModeResolvers.set(variable.name, aliasVariableModeResolver = {});
|
|
395
361
|
}
|
|
396
362
|
aliasVariableModeResolver[mode] = ()=>{
|
|
397
363
|
delete aliasVariableModeResolver[mode];
|
|
398
364
|
if (!alias) return;
|
|
399
|
-
const
|
|
400
|
-
const eachAliasModeVariableResolver = aliasVariableModeResolvers.get(baseAlias);
|
|
365
|
+
const eachAliasModeVariableResolver = aliasVariableModeResolvers.get(alias);
|
|
401
366
|
if (eachAliasModeVariableResolver) {
|
|
402
367
|
for (const mode of Object.keys(eachAliasModeVariableResolver)){
|
|
403
368
|
eachAliasModeVariableResolver[mode]?.();
|
|
404
369
|
}
|
|
405
370
|
}
|
|
406
|
-
const aliasVariable = this.variables.get(
|
|
371
|
+
const aliasVariable = this.variables.get(alias);
|
|
407
372
|
if (aliasVariable) {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
373
|
+
let resolvedAlpha;
|
|
374
|
+
if (alpha) {
|
|
375
|
+
const numberAlpha = Number(alpha) * (aliasVariable.alpha || 1);
|
|
376
|
+
if (numberAlpha < 1) resolvedAlpha = numberAlpha;
|
|
377
|
+
}
|
|
378
|
+
const newVariable = {
|
|
379
|
+
...variable,
|
|
380
|
+
type: aliasVariable.type,
|
|
381
|
+
value: aliasVariable.value
|
|
382
|
+
};
|
|
383
|
+
if (aliasVariable.type === 'color') {
|
|
384
|
+
if (resolvedAlpha !== undefined) newVariable.alpha = resolvedAlpha;
|
|
385
|
+
if (aliasVariable.space) {
|
|
386
|
+
newVariable.space = aliasVariable.space;
|
|
416
387
|
}
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
...variable.type === 'color' ? {
|
|
424
|
-
space: variable.space
|
|
425
|
-
} : {}
|
|
426
|
-
};
|
|
427
|
-
addVariable(name, newVariable, undefined, modeSuffix);
|
|
388
|
+
}
|
|
389
|
+
addVariable(newVariable.name, newVariable, mode);
|
|
390
|
+
if (aliasVariable.modes) {
|
|
391
|
+
for(const eachMode in aliasVariable.modes){
|
|
392
|
+
const aliasModeVariable = aliasVariable.modes[eachMode];
|
|
393
|
+
addVariable(newVariable.name, aliasModeVariable, eachMode);
|
|
428
394
|
}
|
|
429
395
|
}
|
|
430
396
|
}
|
|
431
397
|
};
|
|
432
398
|
} else {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
399
|
+
// 1. HEX
|
|
400
|
+
const hexMatch = /^#([a-f0-9]{3,4}|[a-f0-9]{6}|[a-f0-9]{8})$/i.exec(variable.value);
|
|
401
|
+
if (hexMatch) {
|
|
402
|
+
const [r, g, b, a] = hexToRgb(hexMatch[1]);
|
|
403
|
+
const newVariable = {
|
|
404
|
+
...variable,
|
|
437
405
|
type: 'color',
|
|
438
|
-
value: `${r} ${g} ${b}
|
|
406
|
+
value: `${r} ${g} ${b}`,
|
|
439
407
|
space: 'rgb'
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
408
|
+
};
|
|
409
|
+
if (a !== undefined && a < 1) {
|
|
410
|
+
newVariable.alpha = a;
|
|
411
|
+
}
|
|
412
|
+
addVariable(newVariable.name, newVariable, mode);
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
// 2. COLOR FUNCTION
|
|
416
|
+
const funcMatch = /^(color|color-contrast|color-mix|hwb|lab|lch|oklab|oklch|rgb|hsl|light-dark)\((.+)\)$/i.exec(variable.value);
|
|
417
|
+
if (funcMatch) {
|
|
418
|
+
let [, space, rawArgs] = funcMatch;
|
|
419
|
+
space = space.toLowerCase();
|
|
420
|
+
const normalizedArgs = rawArgs.replace(/\s*\/\s*/g, '/').replace(/\s*,\s*/g, ' ').replace(/\s+/g, ' ').trim();
|
|
421
|
+
let alpha;
|
|
422
|
+
const alphaMatch = /^(.+?)\/([^\s]+)$/.exec(normalizedArgs);
|
|
423
|
+
const finalArgs = alphaMatch ? alphaMatch[1].trim() : normalizedArgs;
|
|
424
|
+
alpha = alphaMatch ? Number(alphaMatch[2]) : undefined;
|
|
425
|
+
const newVariable = {
|
|
426
|
+
...variable,
|
|
427
|
+
type: 'color',
|
|
428
|
+
value: finalArgs,
|
|
429
|
+
space
|
|
430
|
+
};
|
|
431
|
+
if (alpha !== undefined) {
|
|
432
|
+
newVariable.alpha = alpha;
|
|
463
433
|
}
|
|
434
|
+
addVariable(newVariable.name, newVariable, mode);
|
|
435
|
+
return;
|
|
464
436
|
}
|
|
437
|
+
// 3. Fallback
|
|
438
|
+
addVariable(variable.name, {
|
|
439
|
+
...variable,
|
|
440
|
+
type: 'string'
|
|
441
|
+
}, mode);
|
|
465
442
|
}
|
|
466
443
|
}
|
|
467
444
|
};
|
|
468
445
|
if (variables) {
|
|
469
446
|
for(const parnetKey in variables){
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
]);
|
|
447
|
+
const variable = variables[parnetKey];
|
|
448
|
+
resolveVariable(variable);
|
|
473
449
|
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
450
|
+
}
|
|
451
|
+
if (modes) {
|
|
452
|
+
for(const mode in modes){
|
|
453
|
+
const modeVariables = modes[mode];
|
|
454
|
+
if (!modeVariables) continue;
|
|
455
|
+
for(const key in modeVariables){
|
|
456
|
+
const variable = modeVariables[key];
|
|
457
|
+
resolveVariable(variable, mode);
|
|
478
458
|
}
|
|
479
|
-
}
|
|
459
|
+
}
|
|
480
460
|
}
|
|
461
|
+
// todo: address to the target variable
|
|
462
|
+
aliasVariableModeResolvers.forEach((aliasVariableModeResolver)=>{
|
|
463
|
+
for (const mode of Object.keys(aliasVariableModeResolver)){
|
|
464
|
+
aliasVariableModeResolver[mode]?.();
|
|
465
|
+
}
|
|
466
|
+
});
|
|
481
467
|
if (screens) {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
468
|
+
for(const key in screens){
|
|
469
|
+
const value = screens[key];
|
|
470
|
+
const name = 'screen-' + key;
|
|
471
|
+
this.variables.set(name, {
|
|
472
|
+
name,
|
|
473
|
+
key,
|
|
474
|
+
namespace: 'screen',
|
|
475
|
+
group: 'screen',
|
|
476
|
+
type: 'number',
|
|
477
|
+
value
|
|
478
|
+
});
|
|
479
|
+
this.variables.set('-' + name, {
|
|
480
|
+
name: '-' + name,
|
|
481
|
+
key: '-' + key,
|
|
482
|
+
namespace: 'screen',
|
|
483
|
+
group: 'screen',
|
|
484
|
+
type: 'number',
|
|
485
|
+
value: value * -1
|
|
486
|
+
});
|
|
487
|
+
}
|
|
485
488
|
}
|
|
486
489
|
}
|
|
487
490
|
parseValue(token, unit = 'rem') {
|
|
@@ -500,7 +503,7 @@ class MasterCSS {
|
|
|
500
503
|
}
|
|
501
504
|
/**
|
|
502
505
|
* 2. value (ambiguous.key * ambiguous.values)
|
|
503
|
-
* @example bg:current box
|
|
506
|
+
* @example bg:current box-content font:12
|
|
504
507
|
*/ for (const eachSyntax of this.definedRules){
|
|
505
508
|
if (eachSyntax.matchers.value?.test(className)) return eachSyntax;
|
|
506
509
|
}
|
|
@@ -654,14 +657,11 @@ class MasterCSS {
|
|
|
654
657
|
}
|
|
655
658
|
}
|
|
656
659
|
getModeSelector(modeName) {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
case 'host':
|
|
663
|
-
return ':host(.' + modeName + ')';
|
|
664
|
-
}
|
|
660
|
+
switch(this.config.modeTrigger){
|
|
661
|
+
case 'class':
|
|
662
|
+
return '.' + modeName;
|
|
663
|
+
case 'host':
|
|
664
|
+
return ':host(.' + modeName + ')';
|
|
665
665
|
}
|
|
666
666
|
}
|
|
667
667
|
}
|
package/dist/create.cjs
ADDED
package/dist/create.d.ts
ADDED