@master/css 2.0.0-rc.57 → 2.0.0-rc.59
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/config/functions.cjs +1 -1
- package/dist/config/functions.mjs +1 -1
- package/dist/core.cjs +113 -113
- package/dist/core.d.ts +62 -12
- package/dist/core.mjs +113 -113
- package/dist/factories/with-syntax-layer.cjs +308 -0
- package/dist/factories/with-syntax-layer.d.ts +26 -0
- package/dist/factories/with-syntax-layer.mjs +306 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +1 -0
- package/dist/layer.cjs +12 -79
- package/dist/layer.d.ts +3 -2
- package/dist/layer.mjs +12 -79
- package/dist/non-layer.cjs +3 -4
- package/dist/non-layer.d.ts +1 -1
- package/dist/non-layer.mjs +3 -4
- package/dist/syntax-layer.cjs +2 -288
- package/dist/syntax-layer.d.ts +17 -16
- package/dist/syntax-layer.mjs +2 -288
- package/dist/syntax-rule.cjs +9 -8
- package/dist/syntax-rule.mjs +9 -8
- package/dist/utils/extend-config.cjs +32 -46
- package/dist/utils/extend-config.mjs +32 -46
- package/dist/utils/flatten-object.d.ts +1 -1
- package/package.json +1 -1
|
@@ -182,7 +182,7 @@ const functions = {
|
|
|
182
182
|
const isVarFunction = functionName === '$' || functionName === 'var';
|
|
183
183
|
childHasUnit = anaylzeDeeply(newValueComponent.children, functionName !== '' && functionName !== 'calc' && (isVarFunction || Object.prototype.hasOwnProperty.call(functions, functionName)), bypassParsing || isVarFunction || unitChecking && currentHasUnit, unitChecking, isVarFunction) || functionName === 'var';
|
|
184
184
|
if (!childHasUnit && functionName === '$') {
|
|
185
|
-
const variableType = this.css.variables
|
|
185
|
+
const variableType = this.css.variables.get(newValueComponent.children[0].value)?.type;
|
|
186
186
|
childHasUnit = !variableType || variableType === 'string';
|
|
187
187
|
}
|
|
188
188
|
if (childHasUnit) {
|
|
@@ -180,7 +180,7 @@ const functions = {
|
|
|
180
180
|
const isVarFunction = functionName === '$' || functionName === 'var';
|
|
181
181
|
childHasUnit = anaylzeDeeply(newValueComponent.children, functionName !== '' && functionName !== 'calc' && (isVarFunction || Object.prototype.hasOwnProperty.call(functions, functionName)), bypassParsing || isVarFunction || unitChecking && currentHasUnit, unitChecking, isVarFunction) || functionName === 'var';
|
|
182
182
|
if (!childHasUnit && functionName === '$') {
|
|
183
|
-
const variableType = this.css.variables
|
|
183
|
+
const variableType = this.css.variables.get(newValueComponent.children[0].value)?.type;
|
|
184
184
|
childHasUnit = !variableType || variableType === 'string';
|
|
185
185
|
}
|
|
186
186
|
if (childHasUnit) {
|
package/dist/core.cjs
CHANGED
|
@@ -5,10 +5,10 @@ var index = require('./config/index.cjs');
|
|
|
5
5
|
var hexToRgb = require('./utils/hex-to-rgb.cjs');
|
|
6
6
|
var flattenObject = require('./utils/flatten-object.cjs');
|
|
7
7
|
var extendConfig = require('./utils/extend-config.cjs');
|
|
8
|
-
var syntaxLayer = require('./syntax-layer.cjs');
|
|
9
8
|
var rule = require('./rule.cjs');
|
|
10
9
|
var syntaxRuleType = require('./syntax-rule-type.cjs');
|
|
11
10
|
var layer = require('./layer.cjs');
|
|
11
|
+
var syntaxLayer = require('./syntax-layer.cjs');
|
|
12
12
|
var nonLayer = require('./non-layer.cjs');
|
|
13
13
|
var registerGlobal = require('./register-global.cjs');
|
|
14
14
|
|
|
@@ -17,7 +17,6 @@ class MasterCSS {
|
|
|
17
17
|
static config = index.config;
|
|
18
18
|
definedRules;
|
|
19
19
|
config;
|
|
20
|
-
classCounts;
|
|
21
20
|
layerStatementRule;
|
|
22
21
|
rules;
|
|
23
22
|
animationsNonLayer;
|
|
@@ -26,25 +25,14 @@ class MasterCSS {
|
|
|
26
25
|
presetLayer;
|
|
27
26
|
componentsLayer;
|
|
28
27
|
generalLayer;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
'theme',
|
|
35
|
-
'preset',
|
|
36
|
-
'components',
|
|
37
|
-
'general'
|
|
38
|
-
];
|
|
39
|
-
const indexA = order.indexOf(a.name) === -1 ? Infinity : order.indexOf(a.name);
|
|
40
|
-
const indexB = order.indexOf(b.name) === -1 ? Infinity : order.indexOf(b.name);
|
|
41
|
-
return indexA - indexB;
|
|
42
|
-
}).map(({ text })=>text).join('');
|
|
43
|
-
}
|
|
28
|
+
components;
|
|
29
|
+
selectors;
|
|
30
|
+
variables;
|
|
31
|
+
at;
|
|
32
|
+
animations;
|
|
44
33
|
constructor(customConfig){
|
|
45
34
|
this.customConfig = customConfig;
|
|
46
35
|
this.definedRules = [];
|
|
47
|
-
this.classCounts = new Map();
|
|
48
36
|
this.layerStatementRule = new rule.Rule('layer-statement', [
|
|
49
37
|
{
|
|
50
38
|
text: '@layer base,theme,preset,components,general;'
|
|
@@ -59,15 +47,35 @@ class MasterCSS {
|
|
|
59
47
|
this.presetLayer = new syntaxLayer('preset', this);
|
|
60
48
|
this.componentsLayer = new syntaxLayer('components', this);
|
|
61
49
|
this.generalLayer = new syntaxLayer('general', this);
|
|
50
|
+
this.components = new Map();
|
|
51
|
+
this.selectors = new Map();
|
|
52
|
+
this.variables = new Map();
|
|
53
|
+
this.at = new Map();
|
|
54
|
+
this.animations = new Map();
|
|
62
55
|
this.config = customConfig?.override ? extendConfig(customConfig) : extendConfig(index.config, customConfig);
|
|
63
56
|
this.resolve();
|
|
64
57
|
}
|
|
58
|
+
get text() {
|
|
59
|
+
return this.rules.sort((a, b)=>{
|
|
60
|
+
const order = [
|
|
61
|
+
'layer-statement',
|
|
62
|
+
'base',
|
|
63
|
+
'theme',
|
|
64
|
+
'preset',
|
|
65
|
+
'components',
|
|
66
|
+
'general'
|
|
67
|
+
];
|
|
68
|
+
const indexA = order.indexOf(a.name) === -1 ? Infinity : order.indexOf(a.name);
|
|
69
|
+
const indexB = order.indexOf(b.name) === -1 ? Infinity : order.indexOf(b.name);
|
|
70
|
+
return indexA - indexB;
|
|
71
|
+
}).map(({ text })=>text).join('');
|
|
72
|
+
}
|
|
65
73
|
resolve() {
|
|
66
|
-
this.components
|
|
67
|
-
this.selectors
|
|
68
|
-
this.variables
|
|
69
|
-
this.at
|
|
70
|
-
this.animations
|
|
74
|
+
this.components.clear();
|
|
75
|
+
this.selectors.clear();
|
|
76
|
+
this.variables.clear();
|
|
77
|
+
this.at.clear();
|
|
78
|
+
this.animations.clear();
|
|
71
79
|
this.definedRules.length = 0;
|
|
72
80
|
const colorVariableNames = {
|
|
73
81
|
current: undefined,
|
|
@@ -87,9 +95,9 @@ class MasterCSS {
|
|
|
87
95
|
eachResolvedSelectorText
|
|
88
96
|
]){
|
|
89
97
|
const vendor = eachNewSelectorText.match(/^:(?::)?-(webkit|moz|ms|o)-/m)?.[1] ?? '';
|
|
90
|
-
let selectorValues = this.selectors
|
|
98
|
+
let selectorValues = this.selectors.get(vendor);
|
|
91
99
|
if (!selectorValues) {
|
|
92
|
-
|
|
100
|
+
this.selectors.set(vendor, selectorValues = []);
|
|
93
101
|
}
|
|
94
102
|
let currentSelectValue = selectorValues.find(([_valueRegexp])=>_valueRegexp === regexp);
|
|
95
103
|
if (!currentSelectValue) {
|
|
@@ -104,7 +112,7 @@ class MasterCSS {
|
|
|
104
112
|
}
|
|
105
113
|
}
|
|
106
114
|
if (variables) {
|
|
107
|
-
const
|
|
115
|
+
const aliasVariableModeResolvers = new Map;
|
|
108
116
|
const resolveVariable = (variableDefinition, name, mode)=>{
|
|
109
117
|
if (variableDefinition === undefined || variableDefinition === null) return;
|
|
110
118
|
const addVariable = (name, variable, replacedMode, alpha)=>{
|
|
@@ -128,12 +136,12 @@ class MasterCSS {
|
|
|
128
136
|
/**
|
|
129
137
|
* resolve `variables.screen-*` to `at.*`
|
|
130
138
|
*/ if (variable.name.startsWith('screen-') && variable.type === 'number') {
|
|
131
|
-
this.at
|
|
139
|
+
this.at.set(variable.name.slice(7), variable.value);
|
|
132
140
|
}
|
|
133
141
|
const currentMode = replacedMode ?? mode;
|
|
134
142
|
if (currentMode !== undefined) {
|
|
135
|
-
|
|
136
|
-
|
|
143
|
+
const foundVariable = this.variables.get(flatName);
|
|
144
|
+
if (foundVariable) {
|
|
137
145
|
if (currentMode) {
|
|
138
146
|
if (!foundVariable.modes) {
|
|
139
147
|
foundVariable.modes = {};
|
|
@@ -159,13 +167,13 @@ class MasterCSS {
|
|
|
159
167
|
if (variable.type === 'color') {
|
|
160
168
|
newVariable.space = variable.space;
|
|
161
169
|
}
|
|
162
|
-
this.variables
|
|
170
|
+
this.variables.set(flatName, newVariable);
|
|
163
171
|
} else {
|
|
164
|
-
this.variables
|
|
172
|
+
this.variables.set(flatName, variable);
|
|
165
173
|
}
|
|
166
174
|
}
|
|
167
175
|
} else {
|
|
168
|
-
this.variables
|
|
176
|
+
this.variables.set(flatName, variable);
|
|
169
177
|
}
|
|
170
178
|
};
|
|
171
179
|
if (typeof variableDefinition === 'object') {
|
|
@@ -203,19 +211,21 @@ class MasterCSS {
|
|
|
203
211
|
const aliasResult = /^\$\((.*?)\)(?: ?\/ ?(.+?))?$/.exec(variableDefinition);
|
|
204
212
|
const flatName = name.join('-');
|
|
205
213
|
if (aliasResult) {
|
|
206
|
-
|
|
207
|
-
|
|
214
|
+
let aliasVariableModeResolver = aliasVariableModeResolvers.get(flatName);
|
|
215
|
+
if (!aliasVariableModeResolver) {
|
|
216
|
+
aliasVariableModeResolvers.set(flatName, aliasVariableModeResolver = {});
|
|
208
217
|
}
|
|
209
|
-
|
|
210
|
-
delete
|
|
218
|
+
aliasVariableModeResolver[mode] = ()=>{
|
|
219
|
+
delete aliasVariableModeResolver[mode];
|
|
211
220
|
const [alias, aliasMode] = aliasResult[1].split('@');
|
|
212
221
|
if (alias) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
222
|
+
const eachAliasModeVariableResolver = aliasVariableModeResolvers.get(alias);
|
|
223
|
+
if (eachAliasModeVariableResolver) {
|
|
224
|
+
for (const mode of Object.keys(eachAliasModeVariableResolver)){
|
|
225
|
+
eachAliasModeVariableResolver[mode]?.();
|
|
216
226
|
}
|
|
217
227
|
}
|
|
218
|
-
const aliasVariable = this.variables
|
|
228
|
+
const aliasVariable = this.variables.get(alias);
|
|
219
229
|
if (aliasVariable) {
|
|
220
230
|
if (aliasMode === undefined && aliasVariable.modes) {
|
|
221
231
|
addVariable(name, {
|
|
@@ -284,18 +294,22 @@ class MasterCSS {
|
|
|
284
294
|
]);
|
|
285
295
|
}
|
|
286
296
|
// todo: address to the target variable
|
|
287
|
-
|
|
288
|
-
for (const mode of Object.keys(
|
|
289
|
-
|
|
297
|
+
aliasVariableModeResolvers.forEach((aliasVariableModeResolver)=>{
|
|
298
|
+
for (const mode of Object.keys(aliasVariableModeResolver)){
|
|
299
|
+
aliasVariableModeResolver[mode]?.();
|
|
290
300
|
}
|
|
291
|
-
}
|
|
301
|
+
});
|
|
292
302
|
}
|
|
293
303
|
if (at) {
|
|
294
|
-
|
|
304
|
+
const resolvedAt = flattenObject.flattenObject(at);
|
|
305
|
+
for(const eachAt in resolvedAt){
|
|
306
|
+
this.at.set(eachAt, resolvedAt[eachAt]);
|
|
307
|
+
}
|
|
295
308
|
}
|
|
296
309
|
if (animations) {
|
|
297
310
|
for(const animationName in animations){
|
|
298
|
-
const eachAnimation =
|
|
311
|
+
const eachAnimation = {};
|
|
312
|
+
this.animations.set(animationName, eachAnimation);
|
|
299
313
|
const eachKeyframes = animations[animationName];
|
|
300
314
|
for(const eachKeyframeValue in eachKeyframes){
|
|
301
315
|
const newValueByPropertyName = eachAnimation[eachKeyframeValue] = {};
|
|
@@ -309,8 +323,9 @@ class MasterCSS {
|
|
|
309
323
|
const flattedStyles = components ? flattenObject.flattenObject(components) : {};
|
|
310
324
|
const utilityNames = Object.keys(flattedStyles);
|
|
311
325
|
const handleUtilityName = (utilityName)=>{
|
|
312
|
-
if (
|
|
313
|
-
const currentClass =
|
|
326
|
+
if (this.components.has(utilityName)) return;
|
|
327
|
+
const currentClass = [];
|
|
328
|
+
this.components.set(utilityName, currentClass);
|
|
314
329
|
const className = flattedStyles[utilityName];
|
|
315
330
|
if (!className) return;
|
|
316
331
|
const classNames = className.replace(/(?:\n(?:\s*))+/g, ' ').trim().split(' ');
|
|
@@ -322,9 +337,8 @@ class MasterCSS {
|
|
|
322
337
|
};
|
|
323
338
|
if (utilityNames.includes(eachClassName)) {
|
|
324
339
|
handleUtilityName(eachClassName);
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
}
|
|
340
|
+
const componentClasses = this.components.get(eachClassName);
|
|
341
|
+
componentClasses?.forEach(handle);
|
|
328
342
|
} else {
|
|
329
343
|
handle(eachClassName);
|
|
330
344
|
}
|
|
@@ -382,12 +396,11 @@ class MasterCSS {
|
|
|
382
396
|
}
|
|
383
397
|
// todo: 不可使用 startsWith 判斷,應改為更精準的從 config.variables 取得目標變數群組,但 config.variables 中的值還沒被 resolve 像是 Array
|
|
384
398
|
const addResolvedVariables = (groupName)=>{
|
|
385
|
-
|
|
386
|
-
const eachVariable = this.variables[eachVariableName];
|
|
399
|
+
this.variables.forEach((eachVariable)=>{
|
|
387
400
|
if (eachVariable.group === groupName) {
|
|
388
401
|
syntax.variables[eachVariable.key] = eachVariable;
|
|
389
402
|
}
|
|
390
|
-
}
|
|
403
|
+
});
|
|
391
404
|
};
|
|
392
405
|
// 1. custom `config.rules[id].variables`
|
|
393
406
|
if (eachSyntaxRuleDefinition.variables) {
|
|
@@ -443,8 +456,8 @@ class MasterCSS {
|
|
|
443
456
|
}
|
|
444
457
|
});
|
|
445
458
|
}
|
|
446
|
-
|
|
447
|
-
const syntaxRulesByStateToken =
|
|
459
|
+
this.components.forEach((componentClasses, componentClass)=>{
|
|
460
|
+
const syntaxRulesByStateToken = componentClasses.map((eachSyntax)=>this.create(eachSyntax)).filter((eachSyntax)=>eachSyntax?.text).reduce((obj, eachSyntaxRule)=>{
|
|
448
461
|
if (eachSyntaxRule.stateToken in obj) {
|
|
449
462
|
obj[eachSyntaxRule.stateToken].push(eachSyntaxRule);
|
|
450
463
|
} else {
|
|
@@ -454,11 +467,11 @@ class MasterCSS {
|
|
|
454
467
|
}
|
|
455
468
|
return obj;
|
|
456
469
|
}, {});
|
|
457
|
-
this.components
|
|
470
|
+
this.components.set(componentClass, Object.keys(syntaxRulesByStateToken).map((stateToken)=>{
|
|
458
471
|
const syntaxRules = syntaxRulesByStateToken[stateToken];
|
|
459
472
|
return syntaxRules.length === 1 ? syntaxRules[0].name : '{' + syntaxRulesByStateToken[stateToken].map((eachSyntaxRule)=>eachSyntaxRule.name.slice(0, eachSyntaxRule.name.length - eachSyntaxRule.stateToken.length)).join(';') + '}' + stateToken;
|
|
460
|
-
});
|
|
461
|
-
}
|
|
473
|
+
}));
|
|
474
|
+
});
|
|
462
475
|
}
|
|
463
476
|
/**
|
|
464
477
|
* Match check if Master CSS syntax
|
|
@@ -496,27 +509,29 @@ class MasterCSS {
|
|
|
496
509
|
* @returns SyntaxRule[]
|
|
497
510
|
*/ generate(className, mode) {
|
|
498
511
|
let syntaxRules = [];
|
|
499
|
-
|
|
500
|
-
|
|
512
|
+
const componentClasses = this.components.get(className);
|
|
513
|
+
if (componentClasses) {
|
|
514
|
+
componentClasses.forEach((eachSyntax)=>{
|
|
515
|
+
const syntaxRule = this.create(eachSyntax, className, mode);
|
|
516
|
+
if (syntaxRule?.text) syntaxRules.push(syntaxRule);
|
|
517
|
+
});
|
|
501
518
|
} else {
|
|
502
519
|
const atIndex = className.indexOf('@');
|
|
503
520
|
if (atIndex !== -1) {
|
|
504
521
|
const name = className.slice(0, atIndex);
|
|
505
|
-
|
|
522
|
+
const componentClasses = this.components.get(name);
|
|
523
|
+
if (componentClasses) {
|
|
506
524
|
const atToken = className.slice(atIndex);
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
];
|
|
525
|
+
componentClasses.forEach((eachSyntax)=>{
|
|
526
|
+
const syntaxRule = this.create(eachSyntax + atToken, className, mode);
|
|
527
|
+
if (syntaxRule?.text) syntaxRules.push(syntaxRule);
|
|
528
|
+
});
|
|
512
529
|
}
|
|
513
|
-
} else {
|
|
514
|
-
syntaxRules = [
|
|
515
|
-
this.create(className, undefined, mode)
|
|
516
|
-
];
|
|
517
530
|
}
|
|
531
|
+
const syntaxRule = this.create(className, undefined, mode);
|
|
532
|
+
if (syntaxRule?.text) syntaxRules.push(syntaxRule);
|
|
518
533
|
}
|
|
519
|
-
return syntaxRules
|
|
534
|
+
return syntaxRules;
|
|
520
535
|
}
|
|
521
536
|
generateVendorSelectors(selectorText) {
|
|
522
537
|
const vendorSelectors = {};
|
|
@@ -564,14 +579,15 @@ class MasterCSS {
|
|
|
564
579
|
return selectors;
|
|
565
580
|
};
|
|
566
581
|
const transformedSelectors = [];
|
|
567
|
-
|
|
568
|
-
|
|
582
|
+
const selectorValues = this.selectors.get('');
|
|
583
|
+
if (selectorValues) {
|
|
584
|
+
transformSelector(selectorText, selectorValues, transformedSelectors, true);
|
|
569
585
|
} else {
|
|
570
586
|
transformedSelectors.push(selectorText);
|
|
571
587
|
}
|
|
572
588
|
const unspacedVendorSelectors = {};
|
|
573
|
-
|
|
574
|
-
if (!vendor)
|
|
589
|
+
this.selectors.forEach((selectorValues, vendor)=>{
|
|
590
|
+
if (!vendor) return;
|
|
575
591
|
const newUnspacedVendorSelectors = [];
|
|
576
592
|
for (const eachTransformedSelector of transformedSelectors){
|
|
577
593
|
transformSelector(eachTransformedSelector, selectorValues, newUnspacedVendorSelectors, false);
|
|
@@ -579,7 +595,7 @@ class MasterCSS {
|
|
|
579
595
|
if (newUnspacedVendorSelectors.length) {
|
|
580
596
|
unspacedVendorSelectors[vendor] = newUnspacedVendorSelectors;
|
|
581
597
|
}
|
|
582
|
-
}
|
|
598
|
+
});
|
|
583
599
|
const insertVendorSelectors = (vendor, selectorTexts)=>{
|
|
584
600
|
const groupedSelectorTexts = selectorTexts.reduce((arr, eachSuffixSelector)=>{
|
|
585
601
|
arr.push(...spacedSelectorToken(eachSuffixSelector));
|
|
@@ -616,37 +632,26 @@ class MasterCSS {
|
|
|
616
632
|
* @param selectorText
|
|
617
633
|
*/ createFromSelectorText(selectorText) {
|
|
618
634
|
const selectorTextSplits = selectorText.split(' ');
|
|
635
|
+
const stopChars = /[.#\[!\*>+~:,\s]/;
|
|
619
636
|
for(let i = 0; i < selectorTextSplits.length; i++){
|
|
620
637
|
const eachField = selectorTextSplits[i];
|
|
621
638
|
const modeSelector = this.getModeSelector(eachField);
|
|
622
639
|
if (i === 0 && eachField === modeSelector) continue;
|
|
623
|
-
if (eachField
|
|
640
|
+
if (eachField.startsWith('.')) {
|
|
624
641
|
const eachFieldName = eachField.slice(1);
|
|
625
642
|
let className = '';
|
|
626
|
-
|
|
643
|
+
let l = 0;
|
|
644
|
+
while(l < eachFieldName.length){
|
|
627
645
|
const char = eachFieldName[l];
|
|
628
646
|
const nextChar = eachFieldName[l + 1];
|
|
629
|
-
if (char === '\\') {
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
continue;
|
|
634
|
-
}
|
|
635
|
-
} else if ([
|
|
636
|
-
'.',
|
|
637
|
-
'#',
|
|
638
|
-
'[',
|
|
639
|
-
'!',
|
|
640
|
-
'*',
|
|
641
|
-
'>',
|
|
642
|
-
'+',
|
|
643
|
-
'~',
|
|
644
|
-
':',
|
|
645
|
-
','
|
|
646
|
-
].includes(char)) {
|
|
647
|
-
break;
|
|
647
|
+
if (char === '\\' && nextChar) {
|
|
648
|
+
className += nextChar;
|
|
649
|
+
l += 2;
|
|
650
|
+
continue;
|
|
648
651
|
}
|
|
652
|
+
if (stopChars.test(char)) break;
|
|
649
653
|
className += char;
|
|
654
|
+
l++;
|
|
650
655
|
}
|
|
651
656
|
const syntaxRules = this.generate(className);
|
|
652
657
|
if (syntaxRules.length) return syntaxRules;
|
|
@@ -665,12 +670,6 @@ class MasterCSS {
|
|
|
665
670
|
// @ts-ignore
|
|
666
671
|
this.config = customConfig?.override ? extendConfig(customConfig) : extendConfig(index.config, customConfig);
|
|
667
672
|
this.resolve();
|
|
668
|
-
/**
|
|
669
|
-
* 拿當前所有的 classNames 按照最新的 colors, config.rules 匹配並生成新的 style
|
|
670
|
-
* 所以 refresh 過後 rules 可能會變多也可能會變少
|
|
671
|
-
*/ this.classCounts.forEach((_, className)=>{
|
|
672
|
-
this.add(className);
|
|
673
|
-
});
|
|
674
673
|
return this;
|
|
675
674
|
}
|
|
676
675
|
reset() {
|
|
@@ -684,7 +683,6 @@ class MasterCSS {
|
|
|
684
683
|
}
|
|
685
684
|
destroy() {
|
|
686
685
|
this.reset();
|
|
687
|
-
this.classCounts.clear();
|
|
688
686
|
return this;
|
|
689
687
|
}
|
|
690
688
|
add(...classNames) {
|
|
@@ -698,19 +696,21 @@ class MasterCSS {
|
|
|
698
696
|
* class name 從 DOM tree 中被移除,
|
|
699
697
|
* 匹配並刪除對應的 rule
|
|
700
698
|
*/ for (const className of classNames){
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
699
|
+
const componentClasses = this.components.get(className);
|
|
700
|
+
if (componentClasses) {
|
|
701
|
+
componentClasses.forEach((componentClass)=>{
|
|
702
|
+
this.componentsLayer.delete(className + ' ' + componentClass);
|
|
703
|
+
});
|
|
705
704
|
} else {
|
|
706
705
|
const atIndex = className.indexOf('@');
|
|
707
706
|
if (atIndex !== -1) {
|
|
708
707
|
const name = className.slice(0, atIndex);
|
|
709
|
-
|
|
708
|
+
const componentClasses = this.components.get(name);
|
|
709
|
+
if (componentClasses) {
|
|
710
710
|
const atToken = className.slice(atIndex);
|
|
711
|
-
|
|
712
|
-
this.componentsLayer.delete(
|
|
713
|
-
}
|
|
711
|
+
componentClasses.forEach((componentClass)=>{
|
|
712
|
+
this.componentsLayer.delete(componentClass + atToken + ' ' + className);
|
|
713
|
+
});
|
|
714
714
|
} else {
|
|
715
715
|
this.generalLayer.delete(className);
|
|
716
716
|
}
|
package/dist/core.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { SyntaxRule } from './syntax-rule';
|
|
2
|
-
import SyntaxLayer from './syntax-layer';
|
|
3
2
|
import { Rule } from './rule';
|
|
4
3
|
import Layer from './layer';
|
|
5
4
|
import NonLayer from './non-layer';
|
|
@@ -11,17 +10,73 @@ export default class MasterCSS {
|
|
|
11
10
|
static config: Config;
|
|
12
11
|
readonly definedRules: DefinedRule[];
|
|
13
12
|
readonly config: Config;
|
|
14
|
-
readonly classCounts: Map<string, number>;
|
|
15
13
|
readonly layerStatementRule: Rule;
|
|
16
14
|
readonly rules: (Layer | Rule)[];
|
|
17
15
|
readonly animationsNonLayer: NonLayer;
|
|
18
|
-
readonly baseLayer:
|
|
16
|
+
readonly baseLayer: {
|
|
17
|
+
rules: SyntaxRule[];
|
|
18
|
+
insert(syntaxRule: SyntaxRule): number | undefined;
|
|
19
|
+
delete(key: string): SyntaxRule | undefined;
|
|
20
|
+
insertVariables(syntaxRule: SyntaxRule): void;
|
|
21
|
+
insertAnimations(syntaxRule: SyntaxRule): void;
|
|
22
|
+
readonly tokenCounts: Map<string, number>;
|
|
23
|
+
name: string;
|
|
24
|
+
css: MasterCSS;
|
|
25
|
+
attach(): void;
|
|
26
|
+
detach(): void;
|
|
27
|
+
reset(): void;
|
|
28
|
+
readonly text: string;
|
|
29
|
+
} & Layer;
|
|
19
30
|
readonly themeLayer: Layer;
|
|
20
|
-
readonly presetLayer:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
readonly presetLayer: {
|
|
32
|
+
rules: SyntaxRule[];
|
|
33
|
+
insert(syntaxRule: SyntaxRule): number | undefined;
|
|
34
|
+
delete(key: string): SyntaxRule | undefined;
|
|
35
|
+
insertVariables(syntaxRule: SyntaxRule): void;
|
|
36
|
+
insertAnimations(syntaxRule: SyntaxRule): void;
|
|
37
|
+
readonly tokenCounts: Map<string, number>;
|
|
38
|
+
name: string;
|
|
39
|
+
css: MasterCSS;
|
|
40
|
+
attach(): void;
|
|
41
|
+
detach(): void;
|
|
42
|
+
reset(): void;
|
|
43
|
+
readonly text: string;
|
|
44
|
+
} & Layer;
|
|
45
|
+
readonly componentsLayer: {
|
|
46
|
+
rules: SyntaxRule[];
|
|
47
|
+
insert(syntaxRule: SyntaxRule): number | undefined;
|
|
48
|
+
delete(key: string): SyntaxRule | undefined;
|
|
49
|
+
insertVariables(syntaxRule: SyntaxRule): void;
|
|
50
|
+
insertAnimations(syntaxRule: SyntaxRule): void;
|
|
51
|
+
readonly tokenCounts: Map<string, number>;
|
|
52
|
+
name: string;
|
|
53
|
+
css: MasterCSS;
|
|
54
|
+
attach(): void;
|
|
55
|
+
detach(): void;
|
|
56
|
+
reset(): void;
|
|
57
|
+
readonly text: string;
|
|
58
|
+
} & Layer;
|
|
59
|
+
readonly generalLayer: {
|
|
60
|
+
rules: SyntaxRule[];
|
|
61
|
+
insert(syntaxRule: SyntaxRule): number | undefined;
|
|
62
|
+
delete(key: string): SyntaxRule | undefined;
|
|
63
|
+
insertVariables(syntaxRule: SyntaxRule): void;
|
|
64
|
+
insertAnimations(syntaxRule: SyntaxRule): void;
|
|
65
|
+
readonly tokenCounts: Map<string, number>;
|
|
66
|
+
name: string;
|
|
67
|
+
css: MasterCSS;
|
|
68
|
+
attach(): void;
|
|
69
|
+
detach(): void;
|
|
70
|
+
reset(): void;
|
|
71
|
+
readonly text: string;
|
|
72
|
+
} & Layer;
|
|
73
|
+
readonly components: Map<string, string[]>;
|
|
74
|
+
readonly selectors: Map<string, [RegExp, string[]][]>;
|
|
75
|
+
readonly variables: Map<string, Variable>;
|
|
76
|
+
readonly at: Map<string, string | number>;
|
|
77
|
+
readonly animations: Map<string, AnimationDefinitions>;
|
|
24
78
|
constructor(customConfig?: Config | undefined);
|
|
79
|
+
get text(): string;
|
|
25
80
|
resolve(): void;
|
|
26
81
|
/**
|
|
27
82
|
* Match check if Master CSS syntax
|
|
@@ -60,9 +115,4 @@ export default class MasterCSS {
|
|
|
60
115
|
export default interface MasterCSS {
|
|
61
116
|
supportVendors: Set<Vendors>;
|
|
62
117
|
style: HTMLStyleElement | null;
|
|
63
|
-
components: Record<string, string[]>;
|
|
64
|
-
selectors: Record<string, [RegExp, string[]][]>;
|
|
65
|
-
variables: Record<string, Variable>;
|
|
66
|
-
at: Record<string, string | number>;
|
|
67
|
-
animations: Record<string, AnimationDefinitions>;
|
|
68
118
|
}
|