@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
package/dist/syntax-layer.mjs
CHANGED
|
@@ -1,292 +1,6 @@
|
|
|
1
|
+
import withSyntaxLayer from './factories/with-syntax-layer.mjs';
|
|
1
2
|
import Layer from './layer.mjs';
|
|
2
|
-
import { Rule } from './rule.mjs';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
rules = [];
|
|
6
|
-
/**
|
|
7
|
-
* normal
|
|
8
|
-
* normal selectors
|
|
9
|
-
* media normal
|
|
10
|
-
* media selectors
|
|
11
|
-
* media width
|
|
12
|
-
* media width selectors
|
|
13
|
-
*/ insert(syntaxRule) {
|
|
14
|
-
if (this.rules.includes(syntaxRule)) return;
|
|
15
|
-
let index;
|
|
16
|
-
/**
|
|
17
|
-
* 必須按斷點值遞增,並透過索引插入,
|
|
18
|
-
* 以實現響應式先後套用的規則
|
|
19
|
-
* @example <1 <2 <3 ALL >=1 >=2 >=3
|
|
20
|
-
* @description
|
|
21
|
-
*/ const endIndex = this.rules.length - 1;
|
|
22
|
-
const { at, atToken, order, priority } = syntaxRule;
|
|
23
|
-
const findIndex = (startIndex, stopCheck, matchCheck)=>{
|
|
24
|
-
let i = startIndex;
|
|
25
|
-
for(; i <= endIndex; i++){
|
|
26
|
-
const eachSyntaxRule = this.rules[i];
|
|
27
|
-
if (stopCheck?.(eachSyntaxRule)) return matchCheck ? -1 : i - 1;
|
|
28
|
-
if (matchCheck?.(eachSyntaxRule)) return i;
|
|
29
|
-
}
|
|
30
|
-
return matchCheck ? -1 : i - 1;
|
|
31
|
-
};
|
|
32
|
-
let matchStartIndex;
|
|
33
|
-
let matchEndIndex;
|
|
34
|
-
if (atToken) {
|
|
35
|
-
const mediaStartIndex = this.rules.findIndex((eachSyntaxRule)=>eachSyntaxRule.at?.media);
|
|
36
|
-
if (mediaStartIndex === -1) {
|
|
37
|
-
index = endIndex + 1;
|
|
38
|
-
} else {
|
|
39
|
-
const maxWidthFeature = at.media?.find(({ name })=>name === 'max-width');
|
|
40
|
-
const minWidthFeature = at.media?.find(({ name })=>name === 'min-width');
|
|
41
|
-
if (maxWidthFeature || minWidthFeature) {
|
|
42
|
-
const mediaWidthStartIndex = this.rules.findIndex((eachSyntaxRule)=>eachSyntaxRule.at?.media?.find(({ name })=>name === 'max-width' || name === 'min-width'));
|
|
43
|
-
if (mediaWidthStartIndex === -1) {
|
|
44
|
-
index = endIndex + 1;
|
|
45
|
-
} else {
|
|
46
|
-
if (maxWidthFeature && minWidthFeature) {
|
|
47
|
-
/**
|
|
48
|
-
* 範圍越小 ( 越限定 越侷限 ) 越優先,
|
|
49
|
-
* 按照範圍 max-width - min-width 遞減排序
|
|
50
|
-
* find 第一個所遇到同樣 feature 且範圍值比自己大的 rule,
|
|
51
|
-
* 並插入在該 rule 之後,讓自己優先被套用
|
|
52
|
-
*/ if (priority === -1) {
|
|
53
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.priority !== -1, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width'));
|
|
54
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.priority !== -1);
|
|
55
|
-
} else {
|
|
56
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, undefined, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1);
|
|
57
|
-
matchEndIndex = endIndex;
|
|
58
|
-
}
|
|
59
|
-
if (matchStartIndex !== -1) {
|
|
60
|
-
const range = maxWidthFeature.value - minWidthFeature.value;
|
|
61
|
-
let i = matchEndIndex;
|
|
62
|
-
const endI = matchStartIndex;
|
|
63
|
-
matchStartIndex = matchEndIndex + 1;
|
|
64
|
-
for(; i >= endI; i--){
|
|
65
|
-
const eachSyntaxRule = this.rules[i];
|
|
66
|
-
const eachMaxWidthFeature = eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width');
|
|
67
|
-
const eachMinWidthFeature = eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width');
|
|
68
|
-
if (!eachMaxWidthFeature || !eachMinWidthFeature) {
|
|
69
|
-
break;
|
|
70
|
-
} else {
|
|
71
|
-
const eachRange = eachMaxWidthFeature.value - eachMinWidthFeature.value;
|
|
72
|
-
if (eachRange < range) {
|
|
73
|
-
matchEndIndex = i - 1;
|
|
74
|
-
} else if (eachRange === range) {
|
|
75
|
-
matchStartIndex = i;
|
|
76
|
-
} else {
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
} else if (minWidthFeature) {
|
|
83
|
-
/**
|
|
84
|
-
* find 第一個所遇到同樣 feature 且值比自己大的 rule,
|
|
85
|
-
* 並插入在該 rule 之後,讓自己優先被套用
|
|
86
|
-
*/ if (priority === -1) {
|
|
87
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') || eachSyntaxRule.priority !== -1, (eachSyntaxRule)=>!eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width'));
|
|
88
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') || eachSyntaxRule.priority !== -1);
|
|
89
|
-
} else {
|
|
90
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1, (eachSyntaxRule)=>!eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1);
|
|
91
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1);
|
|
92
|
-
}
|
|
93
|
-
if (matchStartIndex !== -1) {
|
|
94
|
-
for(let i = matchEndIndex; i >= matchStartIndex; i--){
|
|
95
|
-
const value = (this.rules[i].at.media?.find(({ name })=>name === 'min-width')).value;
|
|
96
|
-
if (value > minWidthFeature.value) {
|
|
97
|
-
matchEndIndex = i - 1;
|
|
98
|
-
} else if (value < minWidthFeature.value) {
|
|
99
|
-
matchStartIndex = i + 1;
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
} else {
|
|
105
|
-
/**
|
|
106
|
-
* find 第一個所遇到同樣 feature 且值比自己大的 rule,
|
|
107
|
-
* 並插入在該 rule 之後,讓自己優先被套用
|
|
108
|
-
*/ if (priority === -1) {
|
|
109
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') || eachSyntaxRule.priority !== -1, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width'));
|
|
110
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') || eachSyntaxRule.priority !== -1);
|
|
111
|
-
} else {
|
|
112
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.priority !== -1);
|
|
113
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1);
|
|
114
|
-
}
|
|
115
|
-
if (matchStartIndex !== -1) {
|
|
116
|
-
for(let i = matchEndIndex; i >= matchStartIndex; i--){
|
|
117
|
-
const value = (this.rules[i].at.media?.find(({ name })=>name === 'max-width')).value;
|
|
118
|
-
if (value < maxWidthFeature.value) {
|
|
119
|
-
matchEndIndex = i - 1;
|
|
120
|
-
} else if (value > maxWidthFeature.value) {
|
|
121
|
-
matchStartIndex = i + 1;
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
} else {
|
|
129
|
-
if (priority === -1) {
|
|
130
|
-
matchStartIndex = mediaStartIndex;
|
|
131
|
-
matchEndIndex = findIndex(mediaStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width') || eachSyntaxRule.priority !== -1);
|
|
132
|
-
} else {
|
|
133
|
-
matchStartIndex = findIndex(mediaStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width'), (eachSyntaxRule)=>eachSyntaxRule.priority !== -1);
|
|
134
|
-
matchEndIndex = findIndex(mediaStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width'));
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
} else {
|
|
139
|
-
if (priority === -1) {
|
|
140
|
-
matchStartIndex = 0;
|
|
141
|
-
matchEndIndex = findIndex(0, (eachSyntax)=>eachSyntax.atToken || eachSyntax.priority !== -1);
|
|
142
|
-
} else {
|
|
143
|
-
matchStartIndex = findIndex(0, (eachSyntax)=>eachSyntax.atToken, (eachSyntax)=>eachSyntax.priority !== -1);
|
|
144
|
-
matchEndIndex = findIndex(0, (eachSyntax)=>eachSyntax.atToken);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
if (index === undefined && matchEndIndex !== undefined && matchStartIndex !== undefined) {
|
|
148
|
-
if (matchStartIndex === -1) {
|
|
149
|
-
index = matchEndIndex + 1;
|
|
150
|
-
} else {
|
|
151
|
-
if (priority === -1) {
|
|
152
|
-
for(let i = matchStartIndex; i <= matchEndIndex; i++){
|
|
153
|
-
const currentSyntaxRule = this.rules[i];
|
|
154
|
-
if (currentSyntaxRule.order >= order) {
|
|
155
|
-
index = i;
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
} else {
|
|
160
|
-
for(let i = matchStartIndex; i <= matchEndIndex; i++){
|
|
161
|
-
const currentSyntaxRule = this.rules[i];
|
|
162
|
-
if (currentSyntaxRule.priority < priority) {
|
|
163
|
-
index = i;
|
|
164
|
-
break;
|
|
165
|
-
} else if (currentSyntaxRule.priority === priority) {
|
|
166
|
-
if (currentSyntaxRule.order >= order) {
|
|
167
|
-
index = i;
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
} else {
|
|
171
|
-
index = i + 1;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
if (index === undefined) {
|
|
176
|
-
index = matchEndIndex + 1;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
super.insert(syntaxRule, index);
|
|
181
|
-
this.insertVariables(syntaxRule);
|
|
182
|
-
this.insertAnimations(syntaxRule);
|
|
183
|
-
syntaxRule.definition.insert?.call(syntaxRule);
|
|
184
|
-
return index;
|
|
185
|
-
}
|
|
186
|
-
delete(key) {
|
|
187
|
-
const syntaxRule = super.delete(key);
|
|
188
|
-
if (!syntaxRule) return;
|
|
189
|
-
if (syntaxRule.variableNames) {
|
|
190
|
-
for (const eachVariableName of syntaxRule.variableNames){
|
|
191
|
-
if (!--this.css.themeLayer.usages[eachVariableName]) {
|
|
192
|
-
this.css.themeLayer.delete(eachVariableName);
|
|
193
|
-
delete this.css.themeLayer.usages[eachVariableName];
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
if (syntaxRule.animationNames) {
|
|
198
|
-
for (const eachKeyframeName of syntaxRule.animationNames){
|
|
199
|
-
if (!--this.css.animationsNonLayer.usages[eachKeyframeName]) {
|
|
200
|
-
this.css.animationsNonLayer.delete(eachKeyframeName);
|
|
201
|
-
delete this.css.animationsNonLayer.usages[eachKeyframeName];
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
syntaxRule.definition.delete?.call(syntaxRule, syntaxRule.name);
|
|
206
|
-
return syntaxRule;
|
|
207
|
-
}
|
|
208
|
-
insertVariables(syntaxRule) {
|
|
209
|
-
if (syntaxRule.variableNames) {
|
|
210
|
-
for (const eachVariableName of syntaxRule.variableNames){
|
|
211
|
-
const variable = this.css.variables[eachVariableName];
|
|
212
|
-
if (this.css.themeLayer.rules.find(({ name })=>name === eachVariableName)) {
|
|
213
|
-
this.css.themeLayer.usages[eachVariableName]++;
|
|
214
|
-
} else {
|
|
215
|
-
const newRule = new Rule(eachVariableName);
|
|
216
|
-
const addNative = (mode, _variable)=>{
|
|
217
|
-
let isDefaultMode = false;
|
|
218
|
-
let preifxCssRuleText;
|
|
219
|
-
let selectorText;
|
|
220
|
-
let endCurlyBracketCount = 1;
|
|
221
|
-
if (mode) {
|
|
222
|
-
switch(this.css.config.modes?.[mode]){
|
|
223
|
-
case 'media':
|
|
224
|
-
selectorText = ':root';
|
|
225
|
-
preifxCssRuleText = `@media(prefers-color-scheme:${mode}){${selectorText}`;
|
|
226
|
-
endCurlyBracketCount++;
|
|
227
|
-
break;
|
|
228
|
-
case 'host':
|
|
229
|
-
preifxCssRuleText = selectorText = `:host(.${mode})`;
|
|
230
|
-
if (!variable.value && this.css.config.defaultMode === mode) {
|
|
231
|
-
preifxCssRuleText += ',:host';
|
|
232
|
-
isDefaultMode = true;
|
|
233
|
-
}
|
|
234
|
-
break;
|
|
235
|
-
case 'class':
|
|
236
|
-
preifxCssRuleText = selectorText = `.${mode}`;
|
|
237
|
-
if (!variable.value && this.css.config.defaultMode === mode) {
|
|
238
|
-
preifxCssRuleText += ',:root';
|
|
239
|
-
isDefaultMode = true;
|
|
240
|
-
}
|
|
241
|
-
break;
|
|
242
|
-
default:
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
} else {
|
|
246
|
-
preifxCssRuleText = selectorText = ':root';
|
|
247
|
-
}
|
|
248
|
-
const cssRuleText = `${preifxCssRuleText}{--${eachVariableName}:${String(_variable.value)}${'}'.repeat(endCurlyBracketCount)}`;
|
|
249
|
-
if (isDefaultMode) {
|
|
250
|
-
newRule.nodes.unshift({
|
|
251
|
-
selectorText,
|
|
252
|
-
text: cssRuleText
|
|
253
|
-
});
|
|
254
|
-
} else {
|
|
255
|
-
newRule.nodes.push({
|
|
256
|
-
text: cssRuleText
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
if (variable.value) {
|
|
261
|
-
addNative('', variable);
|
|
262
|
-
}
|
|
263
|
-
if (variable.modes) {
|
|
264
|
-
for(const mode in variable.modes){
|
|
265
|
-
addNative(mode, variable.modes[mode]);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
this.css.themeLayer.insert(newRule);
|
|
269
|
-
this.css.themeLayer.usages[eachVariableName] = 1;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
insertAnimations(syntaxRule) {
|
|
275
|
-
if (syntaxRule.animationNames) {
|
|
276
|
-
for (const eachAnimationName of syntaxRule.animationNames){
|
|
277
|
-
if (this.css.animationsNonLayer.rules.find(({ name })=>name === eachAnimationName)) {
|
|
278
|
-
this.css.animationsNonLayer.usages[eachAnimationName]++;
|
|
279
|
-
} else {
|
|
280
|
-
this.css.animationsNonLayer.insert(new Rule(eachAnimationName, [
|
|
281
|
-
{
|
|
282
|
-
text: `@keyframes ${eachAnimationName}{` + Object.entries(this.css.animations[eachAnimationName]).map(([key, variables])=>`${key}{${Object.entries(variables).map(([name, value])=>name + ':' + value).join(';')}}`).join('') + '}'
|
|
283
|
-
}
|
|
284
|
-
]));
|
|
285
|
-
this.css.animationsNonLayer.usages[eachAnimationName] = 1;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
4
|
+
const SyntaxLayer = withSyntaxLayer(Layer);
|
|
291
5
|
|
|
292
6
|
export { SyntaxLayer as default };
|
package/dist/syntax-rule.cjs
CHANGED
|
@@ -35,7 +35,7 @@ class SyntaxRule extends rule.Rule {
|
|
|
35
35
|
break;
|
|
36
36
|
// todo: 應挪到 parseValues 階段處理才能支援 variables: { x: 'calc(20vw-30px)' } 這種情況,並且解析上可能會比較合理、精簡
|
|
37
37
|
case 'variable':
|
|
38
|
-
const variable = this.css.variables
|
|
38
|
+
const variable = this.css.variables.get(eachValueComponent.name);
|
|
39
39
|
if (variable) {
|
|
40
40
|
const handleVariable = (normalHandler, varHandler)=>{
|
|
41
41
|
if (variable.modes) {
|
|
@@ -127,7 +127,8 @@ class SyntaxRule extends rule.Rule {
|
|
|
127
127
|
let handled = false;
|
|
128
128
|
if (!isVarFunction || currentValueComponents.length) {
|
|
129
129
|
const handleVariable = (variableName, alpha)=>{
|
|
130
|
-
const
|
|
130
|
+
const globalVariableValue = this.css.variables.get(variableName);
|
|
131
|
+
const variable = Object.prototype.hasOwnProperty.call(this.variables, variableName) ? this.variables[variableName] : globalVariableValue;
|
|
131
132
|
if (variable) {
|
|
132
133
|
const name = variable.name ?? variableName;
|
|
133
134
|
if (!bypassVariableNames.includes(name)) {
|
|
@@ -135,7 +136,7 @@ class SyntaxRule extends rule.Rule {
|
|
|
135
136
|
const valueComponent = {
|
|
136
137
|
type: 'variable',
|
|
137
138
|
name,
|
|
138
|
-
variable: this.css.variables
|
|
139
|
+
variable: this.css.variables.get(name),
|
|
139
140
|
token: currentValue
|
|
140
141
|
};
|
|
141
142
|
if (alpha) valueComponent.alpha = alpha;
|
|
@@ -274,7 +275,7 @@ class SyntaxRule extends rule.Rule {
|
|
|
274
275
|
valueToken = name.slice(indexOfColon + 1);
|
|
275
276
|
}
|
|
276
277
|
this.valueComponents = [];
|
|
277
|
-
const parsedValueIndex = this.parseValues(this.valueComponents, 0, valueToken, unit, '', undefined, false, definition.includeAnimations ?
|
|
278
|
+
const parsedValueIndex = this.parseValues(this.valueComponents, 0, valueToken, unit, '', undefined, false, definition.includeAnimations ? Array.from(this.css.animations.keys()) : []);
|
|
278
279
|
this.valueToken = valueToken.slice(0, parsedValueIndex);
|
|
279
280
|
stateToken = valueToken.slice(parsedValueIndex);
|
|
280
281
|
}
|
|
@@ -373,8 +374,8 @@ class SyntaxRule extends rule.Rule {
|
|
|
373
374
|
value: 'and'
|
|
374
375
|
});
|
|
375
376
|
} else if (atComponentToken.startsWith('')) {
|
|
376
|
-
const targetAt = at
|
|
377
|
-
if (
|
|
377
|
+
const targetAt = at.get(atComponentToken);
|
|
378
|
+
if (typeof targetAt === 'string') {
|
|
378
379
|
const match = targetAt.match(queryTypeRegExp);
|
|
379
380
|
queryType = match ? match[1] : '';
|
|
380
381
|
if (!queryType) throw new Error(`Invalid query '${atComponentToken}': '${targetAt}'`);
|
|
@@ -404,7 +405,7 @@ class SyntaxRule extends rule.Rule {
|
|
|
404
405
|
featureName = 'min-width';
|
|
405
406
|
}
|
|
406
407
|
const token = extremumOperator ? atComponentToken.replace(extremumOperator, '') : atComponentToken;
|
|
407
|
-
const viewport = at
|
|
408
|
+
const viewport = at.get(token);
|
|
408
409
|
switch(featureName){
|
|
409
410
|
case 'max-width':
|
|
410
411
|
case 'min-width':
|
|
@@ -490,7 +491,7 @@ class SyntaxRule extends rule.Rule {
|
|
|
490
491
|
const push = (propertyText)=>{
|
|
491
492
|
// animations
|
|
492
493
|
if (animations && (propertyText.startsWith('animation') || propertyText.startsWith('animation-name'))) {
|
|
493
|
-
const animationNames = propertyText.split(':')[1].split('!important')[0].split(' ').filter((eachValue)=>
|
|
494
|
+
const animationNames = propertyText.split(':')[1].split('!important')[0].split(' ').filter((eachValue)=>this.css.animations.has(eachValue) && (!this.animationNames || !this.animationNames.includes(eachValue)));
|
|
494
495
|
if (animationNames.length) {
|
|
495
496
|
if (!this.animationNames) {
|
|
496
497
|
this.animationNames = [];
|
package/dist/syntax-rule.mjs
CHANGED
|
@@ -33,7 +33,7 @@ class SyntaxRule extends Rule {
|
|
|
33
33
|
break;
|
|
34
34
|
// todo: 應挪到 parseValues 階段處理才能支援 variables: { x: 'calc(20vw-30px)' } 這種情況,並且解析上可能會比較合理、精簡
|
|
35
35
|
case 'variable':
|
|
36
|
-
const variable = this.css.variables
|
|
36
|
+
const variable = this.css.variables.get(eachValueComponent.name);
|
|
37
37
|
if (variable) {
|
|
38
38
|
const handleVariable = (normalHandler, varHandler)=>{
|
|
39
39
|
if (variable.modes) {
|
|
@@ -125,7 +125,8 @@ class SyntaxRule extends Rule {
|
|
|
125
125
|
let handled = false;
|
|
126
126
|
if (!isVarFunction || currentValueComponents.length) {
|
|
127
127
|
const handleVariable = (variableName, alpha)=>{
|
|
128
|
-
const
|
|
128
|
+
const globalVariableValue = this.css.variables.get(variableName);
|
|
129
|
+
const variable = Object.prototype.hasOwnProperty.call(this.variables, variableName) ? this.variables[variableName] : globalVariableValue;
|
|
129
130
|
if (variable) {
|
|
130
131
|
const name = variable.name ?? variableName;
|
|
131
132
|
if (!bypassVariableNames.includes(name)) {
|
|
@@ -133,7 +134,7 @@ class SyntaxRule extends Rule {
|
|
|
133
134
|
const valueComponent = {
|
|
134
135
|
type: 'variable',
|
|
135
136
|
name,
|
|
136
|
-
variable: this.css.variables
|
|
137
|
+
variable: this.css.variables.get(name),
|
|
137
138
|
token: currentValue
|
|
138
139
|
};
|
|
139
140
|
if (alpha) valueComponent.alpha = alpha;
|
|
@@ -272,7 +273,7 @@ class SyntaxRule extends Rule {
|
|
|
272
273
|
valueToken = name.slice(indexOfColon + 1);
|
|
273
274
|
}
|
|
274
275
|
this.valueComponents = [];
|
|
275
|
-
const parsedValueIndex = this.parseValues(this.valueComponents, 0, valueToken, unit, '', undefined, false, definition.includeAnimations ?
|
|
276
|
+
const parsedValueIndex = this.parseValues(this.valueComponents, 0, valueToken, unit, '', undefined, false, definition.includeAnimations ? Array.from(this.css.animations.keys()) : []);
|
|
276
277
|
this.valueToken = valueToken.slice(0, parsedValueIndex);
|
|
277
278
|
stateToken = valueToken.slice(parsedValueIndex);
|
|
278
279
|
}
|
|
@@ -371,8 +372,8 @@ class SyntaxRule extends Rule {
|
|
|
371
372
|
value: 'and'
|
|
372
373
|
});
|
|
373
374
|
} else if (atComponentToken.startsWith('')) {
|
|
374
|
-
const targetAt = at
|
|
375
|
-
if (
|
|
375
|
+
const targetAt = at.get(atComponentToken);
|
|
376
|
+
if (typeof targetAt === 'string') {
|
|
376
377
|
const match = targetAt.match(queryTypeRegExp);
|
|
377
378
|
queryType = match ? match[1] : '';
|
|
378
379
|
if (!queryType) throw new Error(`Invalid query '${atComponentToken}': '${targetAt}'`);
|
|
@@ -402,7 +403,7 @@ class SyntaxRule extends Rule {
|
|
|
402
403
|
featureName = 'min-width';
|
|
403
404
|
}
|
|
404
405
|
const token = extremumOperator ? atComponentToken.replace(extremumOperator, '') : atComponentToken;
|
|
405
|
-
const viewport = at
|
|
406
|
+
const viewport = at.get(token);
|
|
406
407
|
switch(featureName){
|
|
407
408
|
case 'max-width':
|
|
408
409
|
case 'min-width':
|
|
@@ -488,7 +489,7 @@ class SyntaxRule extends Rule {
|
|
|
488
489
|
const push = (propertyText)=>{
|
|
489
490
|
// animations
|
|
490
491
|
if (animations && (propertyText.startsWith('animation') || propertyText.startsWith('animation-name'))) {
|
|
491
|
-
const animationNames = propertyText.split(':')[1].split('!important')[0].split(' ').filter((eachValue)=>
|
|
492
|
+
const animationNames = propertyText.split(':')[1].split('!important')[0].split(' ').filter((eachValue)=>this.css.animations.has(eachValue) && (!this.animationNames || !this.animationNames.includes(eachValue)));
|
|
492
493
|
if (animationNames.length) {
|
|
493
494
|
if (!this.animationNames) {
|
|
494
495
|
this.animationNames = [];
|
|
@@ -7,8 +7,7 @@ function extendConfig(...configs) {
|
|
|
7
7
|
const formatConfig = (config)=>{
|
|
8
8
|
const clonedConfig = extend({}, config);
|
|
9
9
|
const formatDeeply = (obj)=>{
|
|
10
|
-
|
|
11
|
-
const value = obj[key];
|
|
10
|
+
Object.entries(obj).forEach(([key, value])=>{
|
|
12
11
|
if (typeof value === 'object' && !Array.isArray(value)) {
|
|
13
12
|
formatDeeply(value);
|
|
14
13
|
} else if (key && !key.startsWith('@')) {
|
|
@@ -16,58 +15,45 @@ function extendConfig(...configs) {
|
|
|
16
15
|
'': value
|
|
17
16
|
};
|
|
18
17
|
}
|
|
19
|
-
}
|
|
18
|
+
});
|
|
20
19
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
20
|
+
[
|
|
21
|
+
'components',
|
|
22
|
+
'at',
|
|
23
|
+
'variables'
|
|
24
|
+
].forEach((key)=>{
|
|
25
|
+
if (clonedConfig[key]) {
|
|
26
|
+
formatDeeply(clonedConfig[key]);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
30
29
|
return clonedConfig;
|
|
31
30
|
};
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
const collectConfigs = (config, result = [])=>{
|
|
32
|
+
if (!config) return result;
|
|
33
|
+
if (config.extends?.length) {
|
|
34
|
+
config.extends.forEach((ext)=>collectConfigs('config' in ext ? ext.config : ext, result));
|
|
35
|
+
}
|
|
36
|
+
result.push(formatConfig(config));
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
const formattedConfigs = configs.reduce((acc, config)=>collectConfigs(config, acc), []);
|
|
40
|
+
return formattedConfigs.reduce((extendedConfig, currentConfig)=>{
|
|
41
|
+
Object.entries(currentConfig).forEach(([key, value])=>{
|
|
42
|
+
if (key === 'animations' && value) {
|
|
43
|
+
Object.assign(extendedConfig.animations, value);
|
|
44
|
+
} else if (value) {
|
|
45
|
+
extendedConfig = extend(extendedConfig, {
|
|
46
|
+
[key]: value
|
|
47
|
+
});
|
|
40
48
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
let extendedConfig = {
|
|
49
|
+
});
|
|
50
|
+
return extendedConfig;
|
|
51
|
+
}, {
|
|
45
52
|
animations: {},
|
|
46
53
|
components: {},
|
|
47
54
|
at: {},
|
|
48
55
|
variables: {}
|
|
49
|
-
};
|
|
50
|
-
for (const currentFormattedConfig of formattedConfigs){
|
|
51
|
-
for(const key in currentFormattedConfig){
|
|
52
|
-
switch(key){
|
|
53
|
-
case 'animations':
|
|
54
|
-
if (currentFormattedConfig.animations) {
|
|
55
|
-
Object.assign(extendedConfig.animations, currentFormattedConfig.animations);
|
|
56
|
-
}
|
|
57
|
-
break;
|
|
58
|
-
default:
|
|
59
|
-
if (currentFormattedConfig[key]) {
|
|
60
|
-
extendedConfig = extend(extendedConfig, {
|
|
61
|
-
[key]: currentFormattedConfig[key]
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
// if (Object.prototype.hasOwnProperty.call(currentFormattedConfig.components, key)) {
|
|
66
|
-
// Object.assign(extendedConfig.components[key], currentFormattedConfig.components[key])
|
|
67
|
-
// }
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return extendedConfig;
|
|
56
|
+
});
|
|
71
57
|
}
|
|
72
58
|
|
|
73
59
|
module.exports = extendConfig;
|
|
@@ -5,8 +5,7 @@ function extendConfig(...configs) {
|
|
|
5
5
|
const formatConfig = (config)=>{
|
|
6
6
|
const clonedConfig = extend({}, config);
|
|
7
7
|
const formatDeeply = (obj)=>{
|
|
8
|
-
|
|
9
|
-
const value = obj[key];
|
|
8
|
+
Object.entries(obj).forEach(([key, value])=>{
|
|
10
9
|
if (typeof value === 'object' && !Array.isArray(value)) {
|
|
11
10
|
formatDeeply(value);
|
|
12
11
|
} else if (key && !key.startsWith('@')) {
|
|
@@ -14,58 +13,45 @@ function extendConfig(...configs) {
|
|
|
14
13
|
'': value
|
|
15
14
|
};
|
|
16
15
|
}
|
|
17
|
-
}
|
|
16
|
+
});
|
|
18
17
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
18
|
+
[
|
|
19
|
+
'components',
|
|
20
|
+
'at',
|
|
21
|
+
'variables'
|
|
22
|
+
].forEach((key)=>{
|
|
23
|
+
if (clonedConfig[key]) {
|
|
24
|
+
formatDeeply(clonedConfig[key]);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
28
27
|
return clonedConfig;
|
|
29
28
|
};
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
const collectConfigs = (config, result = [])=>{
|
|
30
|
+
if (!config) return result;
|
|
31
|
+
if (config.extends?.length) {
|
|
32
|
+
config.extends.forEach((ext)=>collectConfigs('config' in ext ? ext.config : ext, result));
|
|
33
|
+
}
|
|
34
|
+
result.push(formatConfig(config));
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
const formattedConfigs = configs.reduce((acc, config)=>collectConfigs(config, acc), []);
|
|
38
|
+
return formattedConfigs.reduce((extendedConfig, currentConfig)=>{
|
|
39
|
+
Object.entries(currentConfig).forEach(([key, value])=>{
|
|
40
|
+
if (key === 'animations' && value) {
|
|
41
|
+
Object.assign(extendedConfig.animations, value);
|
|
42
|
+
} else if (value) {
|
|
43
|
+
extendedConfig = extend(extendedConfig, {
|
|
44
|
+
[key]: value
|
|
45
|
+
});
|
|
38
46
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
let extendedConfig = {
|
|
47
|
+
});
|
|
48
|
+
return extendedConfig;
|
|
49
|
+
}, {
|
|
43
50
|
animations: {},
|
|
44
51
|
components: {},
|
|
45
52
|
at: {},
|
|
46
53
|
variables: {}
|
|
47
|
-
};
|
|
48
|
-
for (const currentFormattedConfig of formattedConfigs){
|
|
49
|
-
for(const key in currentFormattedConfig){
|
|
50
|
-
switch(key){
|
|
51
|
-
case 'animations':
|
|
52
|
-
if (currentFormattedConfig.animations) {
|
|
53
|
-
Object.assign(extendedConfig.animations, currentFormattedConfig.animations);
|
|
54
|
-
}
|
|
55
|
-
break;
|
|
56
|
-
default:
|
|
57
|
-
if (currentFormattedConfig[key]) {
|
|
58
|
-
extendedConfig = extend(extendedConfig, {
|
|
59
|
-
[key]: currentFormattedConfig[key]
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// if (Object.prototype.hasOwnProperty.call(currentFormattedConfig.components, key)) {
|
|
64
|
-
// Object.assign(extendedConfig.components[key], currentFormattedConfig.components[key])
|
|
65
|
-
// }
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return extendedConfig;
|
|
54
|
+
});
|
|
69
55
|
}
|
|
70
56
|
|
|
71
57
|
export { extendConfig as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function flattenObject(obj: Record<string, any>, parentKey?: string): Record<string, any>;
|
|
1
|
+
export declare function flattenObject(obj: Map<string, any> | Record<string, any>, parentKey?: string): Record<string, any>;
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@master/css","type":"module","scripts":{"build":"techor build \"src/**/*.ts\"","dev":"pnpm build --watch","test":"vitest","type-check":"tsc --noEmit","lint":"eslint"},"license":"MIT","description":"The CSS language and framework for rapidly building modern and high-performance websites","author":"Aoyue Design LLC.","funding":"https://rc.css.master.co/sponsor","homepage":"https://css.master.co","bugs":{"url":"https://github.com/master-co/css/issues"},"repository":{"type":"git","url":"https://github.com/master-co/css.git","directory":"packages/core"},"keywords":["style","styles","html","variants","virtual","virtual-css","utility","css","ui","lightweight","class","webpack","plugin","integration","vite","parcel","build-tools","mastercss"],"sideEffects":false,"main":"./dist/index.cjs","jsnext:main":"./dist/index.mjs","esnext":"./dist/index.mjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","require":"./dist/index.cjs","import":"./dist/index.mjs"}},"bin":"./dist/bin/index.mjs","files":["dist"],"publishConfig":{"access":"public","provenance":true},"dependencies":{"@master/colors":"^2.1.0","@master/normal.css":"^3.1.0","@techor/extend":"^3.2.0","csstype":"^3.1.3"},"devDependencies":{"shared":"^2.0.0-rc.
|
|
1
|
+
{"name":"@master/css","type":"module","scripts":{"build":"techor build \"src/**/*.ts\"","dev":"pnpm build --watch","test":"vitest","type-check":"tsc --noEmit","lint":"eslint"},"license":"MIT","description":"The CSS language and framework for rapidly building modern and high-performance websites","author":"Aoyue Design LLC.","funding":"https://rc.css.master.co/sponsor","homepage":"https://css.master.co","bugs":{"url":"https://github.com/master-co/css/issues"},"repository":{"type":"git","url":"https://github.com/master-co/css.git","directory":"packages/core"},"keywords":["style","styles","html","variants","virtual","virtual-css","utility","css","ui","lightweight","class","webpack","plugin","integration","vite","parcel","build-tools","mastercss"],"sideEffects":false,"main":"./dist/index.cjs","jsnext:main":"./dist/index.mjs","esnext":"./dist/index.mjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","require":"./dist/index.cjs","import":"./dist/index.mjs"}},"bin":"./dist/bin/index.mjs","files":["dist"],"publishConfig":{"access":"public","provenance":true},"dependencies":{"@master/colors":"^2.1.0","@master/normal.css":"^3.1.0","@techor/extend":"^3.2.0","csstype":"^3.1.3"},"devDependencies":{"shared":"^2.0.0-rc.59"},"version":"2.0.0-rc.59"}
|