@master/css 2.0.0-rc.25 → 2.0.0-rc.27
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 +124 -0
- package/dist/common.d.ts +22 -0
- package/dist/common.mjs +106 -0
- package/dist/config/functions.cjs +40 -41
- package/dist/config/functions.mjs +39 -40
- package/dist/config/index.cjs +7 -7
- package/dist/config/index.d.ts +12 -13
- package/dist/config/index.mjs +6 -6
- package/dist/config/queries.cjs +17 -0
- package/dist/config/queries.d.ts +22 -0
- package/dist/config/queries.mjs +15 -0
- package/dist/config/rules.cjs +964 -851
- package/dist/config/rules.d.ts +8 -5
- package/dist/config/rules.mjs +966 -852
- package/dist/config/selectors.cjs +0 -1
- package/dist/config/selectors.d.ts +0 -1
- package/dist/config/selectors.mjs +0 -1
- package/dist/config/{semantics.cjs → utilities.cjs} +2 -5
- package/dist/config/{semantics.d.ts → utilities.d.ts} +2 -5
- package/dist/config/{semantics.mjs → utilities.mjs} +2 -5
- package/dist/config/variables.mjs +2 -2
- package/dist/core.cjs +260 -195
- package/dist/core.d.ts +20 -16
- package/dist/core.mjs +258 -193
- package/dist/index.cjs +45 -15
- package/dist/index.d.ts +13 -3
- package/dist/index.mjs +15 -7
- package/dist/layer.cjs +25 -20
- package/dist/layer.d.ts +26 -9
- package/dist/layer.mjs +22 -19
- package/dist/rule.cjs +147 -125
- package/dist/rule.d.ts +58 -20
- package/dist/rule.mjs +147 -125
- package/dist/tokens/screen-sizes.cjs +2 -2
- package/dist/tokens/screen-sizes.mjs +2 -2
- package/dist/utils/are-rule-modes-equal.cjs +7 -0
- package/dist/utils/are-rule-modes-equal.d.ts +2 -0
- package/dist/utils/are-rule-modes-equal.mjs +5 -0
- package/dist/utils/are-rule-queries-equal.cjs +22 -0
- package/dist/utils/are-rule-queries-equal.d.ts +2 -0
- package/dist/utils/are-rule-queries-equal.mjs +20 -0
- package/dist/utils/are-rule-selectors-equal.cjs +29 -0
- package/dist/utils/are-rule-selectors-equal.d.ts +2 -0
- package/dist/utils/are-rule-selectors-equal.mjs +27 -0
- package/dist/utils/are-rule-states-equal.cjs +11 -0
- package/dist/utils/are-rule-states-equal.d.ts +2 -0
- package/dist/utils/are-rule-states-equal.mjs +9 -0
- package/dist/utils/are-rules-duplicated.cjs +17 -0
- package/dist/utils/are-rules-duplicated.d.ts +2 -0
- package/dist/utils/are-rules-duplicated.mjs +15 -0
- package/dist/utils/extend-config.cjs +27 -14
- package/dist/utils/extend-config.d.ts +1 -1
- package/dist/utils/extend-config.mjs +27 -14
- package/dist/utils/generate-css.cjs +13 -0
- package/dist/utils/generate-css.d.ts +2 -0
- package/dist/utils/generate-css.mjs +11 -0
- package/dist/utils/hex-to-rgb.cjs +1 -1
- package/dist/utils/hex-to-rgb.d.ts +1 -1
- package/dist/utils/hex-to-rgb.mjs +1 -1
- package/dist/utils/is-core-rule.cjs +9 -0
- package/dist/utils/is-core-rule.d.ts +1 -0
- package/dist/utils/is-core-rule.mjs +7 -0
- package/dist/{functions → utils}/reorder-for-readable-classes.cjs +12 -18
- package/dist/{functions → utils}/reorder-for-readable-classes.d.ts +1 -5
- package/dist/{functions → utils}/reorder-for-readable-classes.mjs +13 -19
- package/package.json +1 -1
- package/dist/config/media-queries.cjs +0 -7
- package/dist/config/media-queries.d.ts +0 -1
- package/dist/config/media-queries.mjs +0 -1
- package/dist/constants/base-unit-regex.cjs +0 -5
- package/dist/constants/base-unit-regex.d.ts +0 -1
- package/dist/constants/base-unit-regex.mjs +0 -3
- package/dist/constants/start-symbol.cjs +0 -10
- package/dist/constants/start-symbol.d.ts +0 -6
- package/dist/constants/start-symbol.mjs +0 -8
- package/dist/functions/transform-color-with-opacity.cjs +0 -9
- package/dist/functions/transform-color-with-opacity.d.ts +0 -1
- package/dist/functions/transform-color-with-opacity.mjs +0 -7
- package/dist/utils/concat-arrays.cjs +0 -12
- package/dist/utils/concat-arrays.d.ts +0 -1
- package/dist/utils/concat-arrays.mjs +0 -10
- package/dist/utils/get-type.cjs +0 -12
- package/dist/utils/get-type.d.ts +0 -7
- package/dist/utils/get-type.mjs +0 -10
- package/dist/utils/is-plain-object.cjs +0 -15
- package/dist/utils/is-plain-object.d.ts +0 -8
- package/dist/utils/is-plain-object.mjs +0 -13
- package/dist/utils/is-symbol.cjs +0 -14
- package/dist/utils/is-symbol.d.ts +0 -7
- package/dist/utils/is-symbol.mjs +0 -12
- package/dist/utils/rgb-to-hex.cjs +0 -7
- package/dist/utils/rgb-to-hex.d.ts +0 -1
- package/dist/utils/rgb-to-hex.mjs +0 -5
package/dist/core.cjs
CHANGED
|
@@ -16,19 +16,17 @@ class MasterCSS {
|
|
|
16
16
|
ruleBy;
|
|
17
17
|
classesUsage;
|
|
18
18
|
config;
|
|
19
|
-
|
|
20
|
-
RegisteredRules;
|
|
19
|
+
Rules;
|
|
21
20
|
constructor(customConfig = index.config){
|
|
22
21
|
this.customConfig = customConfig;
|
|
23
22
|
this.rules = [];
|
|
24
23
|
this.ruleBy = {};
|
|
25
24
|
this.classesUsage = {};
|
|
26
|
-
this.
|
|
27
|
-
this.RegisteredRules = [];
|
|
25
|
+
this.Rules = [];
|
|
28
26
|
if (!customConfig?.override) {
|
|
29
|
-
this.config = extendConfig
|
|
27
|
+
this.config = extendConfig(index.config, customConfig);
|
|
30
28
|
} else {
|
|
31
|
-
this.config = extendConfig
|
|
29
|
+
this.config = extendConfig(customConfig);
|
|
32
30
|
}
|
|
33
31
|
this.resolve();
|
|
34
32
|
if (this.constructor === MasterCSS) {
|
|
@@ -40,10 +38,9 @@ class MasterCSS {
|
|
|
40
38
|
this.stylesBy = {};
|
|
41
39
|
this.selectors = {};
|
|
42
40
|
this.variables = {};
|
|
43
|
-
this.
|
|
41
|
+
this.queries = {};
|
|
44
42
|
this.animations = {};
|
|
45
|
-
this.
|
|
46
|
-
this.RegisteredSemanticRules.length = 0;
|
|
43
|
+
this.Rules.length = 0;
|
|
47
44
|
this.variablesNativeRules = {};
|
|
48
45
|
this.hasKeyframesRule = false;
|
|
49
46
|
const colorVariableNames = {
|
|
@@ -51,7 +48,7 @@ class MasterCSS {
|
|
|
51
48
|
currentColor: undefined,
|
|
52
49
|
transparent: undefined
|
|
53
50
|
};
|
|
54
|
-
const { styles, selectors, variables,
|
|
51
|
+
const { styles, selectors, variables, utilities, queries, rules, animations } = this.config;
|
|
55
52
|
function escapeString(str) {
|
|
56
53
|
return str.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
57
54
|
}
|
|
@@ -82,109 +79,124 @@ class MasterCSS {
|
|
|
82
79
|
}
|
|
83
80
|
if (variables) {
|
|
84
81
|
const unexecutedAliasVariable = {};
|
|
85
|
-
const
|
|
86
|
-
if (!
|
|
87
|
-
const addVariable = (name,
|
|
88
|
-
if (
|
|
89
|
-
|
|
82
|
+
const resolveVariable = (variableDefinition, name, mode)=>{
|
|
83
|
+
if (!variableDefinition === undefined || variableDefinition === null) return;
|
|
84
|
+
const addVariable = (name, variable, replacedMode, alpha)=>{
|
|
85
|
+
if (variable === undefined) return;
|
|
86
|
+
const flatName = name.join('-');
|
|
87
|
+
const groups = name.slice(0, -1).filter(Boolean);
|
|
88
|
+
const key = (name[0] === '' ? '-' : '') + name[name.length - 1];
|
|
89
|
+
variable.key = key;
|
|
90
|
+
variable.name = flatName;
|
|
91
|
+
if (groups.length) variable.group = groups.join('.');
|
|
92
|
+
if (variable.type === 'color') {
|
|
90
93
|
if (alpha) {
|
|
91
|
-
const slashIndex =
|
|
92
|
-
|
|
93
|
-
...
|
|
94
|
-
value: slashIndex === -1 ?
|
|
94
|
+
const slashIndex = variable.value.indexOf('/');
|
|
95
|
+
variable = {
|
|
96
|
+
...variable,
|
|
97
|
+
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)
|
|
95
98
|
};
|
|
96
99
|
}
|
|
97
|
-
colorVariableNames[
|
|
100
|
+
colorVariableNames[flatName] = undefined;
|
|
98
101
|
}
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
101
|
-
if (Object.prototype.hasOwnProperty.call(this.variables,
|
|
102
|
-
const
|
|
103
|
-
if (
|
|
104
|
-
if (!
|
|
105
|
-
|
|
102
|
+
const currentMode = replacedMode ?? mode;
|
|
103
|
+
if (currentMode !== undefined) {
|
|
104
|
+
if (Object.prototype.hasOwnProperty.call(this.variables, flatName)) {
|
|
105
|
+
const foundVariable = this.variables[flatName];
|
|
106
|
+
if (currentMode) {
|
|
107
|
+
if (!foundVariable.modes) {
|
|
108
|
+
foundVariable.modes = {};
|
|
106
109
|
}
|
|
107
|
-
|
|
110
|
+
foundVariable.modes[currentMode] = variable;
|
|
108
111
|
} else {
|
|
109
|
-
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
+
foundVariable.value = variable.value;
|
|
113
|
+
if (variable.type === 'color') {
|
|
114
|
+
foundVariable.space = variable.space;
|
|
112
115
|
}
|
|
113
116
|
}
|
|
114
117
|
} else {
|
|
115
|
-
if (
|
|
118
|
+
if (currentMode) {
|
|
116
119
|
const newVariable = {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
+
key: variable.key,
|
|
121
|
+
name: variable.name,
|
|
122
|
+
group: variable.group,
|
|
123
|
+
type: variable.type,
|
|
124
|
+
modes: {
|
|
125
|
+
[currentMode]: variable
|
|
120
126
|
}
|
|
121
127
|
};
|
|
122
|
-
if (
|
|
123
|
-
newVariable.space =
|
|
128
|
+
if (variable.type === 'color') {
|
|
129
|
+
newVariable.space = variable.space;
|
|
124
130
|
}
|
|
125
|
-
this.variables[
|
|
131
|
+
this.variables[flatName] = newVariable;
|
|
126
132
|
} else {
|
|
127
|
-
this.variables[
|
|
133
|
+
this.variables[flatName] = variable;
|
|
128
134
|
}
|
|
129
135
|
}
|
|
130
136
|
} else {
|
|
131
|
-
this.variables[
|
|
137
|
+
this.variables[flatName] = variable;
|
|
132
138
|
}
|
|
133
139
|
};
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (Array.isArray(variable)) {
|
|
140
|
+
if (typeof variableDefinition === 'object') {
|
|
141
|
+
if (Array.isArray(variableDefinition)) {
|
|
137
142
|
addVariable(name, {
|
|
138
143
|
type: 'string',
|
|
139
|
-
value:
|
|
144
|
+
value: variableDefinition.join(',')
|
|
140
145
|
});
|
|
141
146
|
} else {
|
|
142
|
-
const keys = Object.keys(
|
|
147
|
+
const keys = Object.keys(variableDefinition);
|
|
143
148
|
for (const eachKey of keys){
|
|
144
149
|
if (eachKey === '' || eachKey.startsWith('@')) {
|
|
145
|
-
|
|
150
|
+
resolveVariable(variableDefinition[eachKey], name, eachKey || keys.some((eachKey)=>eachKey.startsWith('@')) ? eachKey.slice(1) : undefined);
|
|
146
151
|
} else {
|
|
147
|
-
|
|
152
|
+
resolveVariable(variableDefinition[eachKey], [
|
|
153
|
+
...name,
|
|
154
|
+
eachKey
|
|
155
|
+
]);
|
|
148
156
|
}
|
|
149
157
|
}
|
|
150
158
|
}
|
|
151
|
-
} else if (
|
|
159
|
+
} else if (typeof variableDefinition === 'number') {
|
|
152
160
|
addVariable(name, {
|
|
153
161
|
type: 'number',
|
|
154
|
-
value:
|
|
162
|
+
value: variableDefinition
|
|
155
163
|
});
|
|
156
|
-
addVariable(
|
|
164
|
+
addVariable([
|
|
165
|
+
'',
|
|
166
|
+
...name
|
|
167
|
+
], {
|
|
157
168
|
type: 'number',
|
|
158
|
-
value:
|
|
169
|
+
value: variableDefinition * -1
|
|
159
170
|
});
|
|
160
|
-
} else if (
|
|
161
|
-
const aliasResult = /^\$\((.*?)\)(?: ?\/ ?(.+?))?$/.exec(
|
|
171
|
+
} else if (typeof variableDefinition === 'string') {
|
|
172
|
+
const aliasResult = /^\$\((.*?)\)(?: ?\/ ?(.+?))?$/.exec(variableDefinition);
|
|
173
|
+
const flatName = name.join('-');
|
|
162
174
|
if (aliasResult) {
|
|
163
|
-
if (!Object.prototype.hasOwnProperty.call(unexecutedAliasVariable,
|
|
164
|
-
unexecutedAliasVariable[
|
|
175
|
+
if (!Object.prototype.hasOwnProperty.call(unexecutedAliasVariable, flatName)) {
|
|
176
|
+
unexecutedAliasVariable[flatName] = {};
|
|
165
177
|
}
|
|
166
|
-
unexecutedAliasVariable[
|
|
167
|
-
delete unexecutedAliasVariable[
|
|
168
|
-
const [alias,
|
|
178
|
+
unexecutedAliasVariable[flatName][mode] = ()=>{
|
|
179
|
+
delete unexecutedAliasVariable[flatName][mode];
|
|
180
|
+
const [alias, aliasMode] = aliasResult[1].split('@');
|
|
169
181
|
if (alias) {
|
|
170
182
|
if (Object.prototype.hasOwnProperty.call(unexecutedAliasVariable, alias)) {
|
|
171
|
-
for (const
|
|
172
|
-
unexecutedAliasVariable[alias][
|
|
183
|
+
for (const mode of Object.keys(unexecutedAliasVariable[alias])){
|
|
184
|
+
unexecutedAliasVariable[alias][mode]?.();
|
|
173
185
|
}
|
|
174
186
|
}
|
|
175
187
|
const aliasVariable = this.variables[alias];
|
|
176
188
|
if (aliasVariable) {
|
|
177
|
-
if (
|
|
189
|
+
if (aliasMode === undefined && aliasVariable.modes) {
|
|
178
190
|
addVariable(name, {
|
|
179
191
|
type: aliasVariable.type,
|
|
180
192
|
value: aliasVariable.value,
|
|
181
193
|
space: aliasVariable.space
|
|
182
194
|
}, '', aliasResult[2]);
|
|
183
|
-
for(const
|
|
184
|
-
addVariable(name, aliasVariable.
|
|
195
|
+
for(const mode in aliasVariable.modes){
|
|
196
|
+
addVariable(name, aliasVariable.modes[mode], mode, aliasResult[2]);
|
|
185
197
|
}
|
|
186
198
|
} else {
|
|
187
|
-
const variable =
|
|
199
|
+
const variable = aliasMode !== undefined ? aliasVariable.modes?.[aliasMode] : aliasVariable;
|
|
188
200
|
if (variable) {
|
|
189
201
|
const newVariable = {
|
|
190
202
|
type: variable.type,
|
|
@@ -200,16 +212,16 @@ class MasterCSS {
|
|
|
200
212
|
}
|
|
201
213
|
};
|
|
202
214
|
} else {
|
|
203
|
-
const hexColorResult = /^#([A-Fa-f0-9]{3,4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.exec(
|
|
215
|
+
const hexColorResult = /^#([A-Fa-f0-9]{3,4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.exec(variableDefinition);
|
|
204
216
|
if (hexColorResult) {
|
|
205
|
-
const [r, g, b, a] = hexToRgb
|
|
217
|
+
const [r, g, b, a] = hexToRgb(hexColorResult[1]);
|
|
206
218
|
addVariable(name, {
|
|
207
219
|
type: 'color',
|
|
208
220
|
value: `${r} ${g} ${b}${a === 1 ? '' : ' / ' + a}`,
|
|
209
221
|
space: 'rgb'
|
|
210
222
|
});
|
|
211
223
|
} else {
|
|
212
|
-
const rgbFunctionResult = /^rgb\( *([0-9]{1,3})(?: *, *| +)([0-9]{1,3})(?: *, *| +)([0-9]{1,3}) *(?:(?:,|\/) *(.*?) *)?\)$/.exec(
|
|
224
|
+
const rgbFunctionResult = /^rgb\( *([0-9]{1,3})(?: *, *| +)([0-9]{1,3})(?: *, *| +)([0-9]{1,3}) *(?:(?:,|\/) *(.*?) *)?\)$/.exec(variableDefinition);
|
|
213
225
|
if (rgbFunctionResult) {
|
|
214
226
|
addVariable(name, {
|
|
215
227
|
type: 'color',
|
|
@@ -217,7 +229,7 @@ class MasterCSS {
|
|
|
217
229
|
space: 'rgb'
|
|
218
230
|
});
|
|
219
231
|
} else {
|
|
220
|
-
const hslFunctionResult = /^hsl\((.*?)\)$/.exec(
|
|
232
|
+
const hslFunctionResult = /^hsl\((.*?)\)$/.exec(variableDefinition);
|
|
221
233
|
if (hslFunctionResult) {
|
|
222
234
|
addVariable(name, {
|
|
223
235
|
type: 'color',
|
|
@@ -227,7 +239,7 @@ class MasterCSS {
|
|
|
227
239
|
} else {
|
|
228
240
|
addVariable(name, {
|
|
229
241
|
type: 'string',
|
|
230
|
-
value:
|
|
242
|
+
value: variableDefinition
|
|
231
243
|
});
|
|
232
244
|
}
|
|
233
245
|
}
|
|
@@ -236,16 +248,19 @@ class MasterCSS {
|
|
|
236
248
|
}
|
|
237
249
|
};
|
|
238
250
|
for(const parnetKey in variables){
|
|
239
|
-
|
|
251
|
+
resolveVariable(variables[parnetKey], [
|
|
252
|
+
parnetKey
|
|
253
|
+
]);
|
|
240
254
|
}
|
|
255
|
+
// todo: address to the target variable
|
|
241
256
|
for (const name of Object.keys(unexecutedAliasVariable)){
|
|
242
|
-
for (const
|
|
243
|
-
unexecutedAliasVariable[name][
|
|
257
|
+
for (const mode of Object.keys(unexecutedAliasVariable[name])){
|
|
258
|
+
unexecutedAliasVariable[name][mode]?.();
|
|
244
259
|
}
|
|
245
260
|
}
|
|
246
261
|
}
|
|
247
|
-
if (
|
|
248
|
-
this.
|
|
262
|
+
if (queries) {
|
|
263
|
+
this.queries = flattenObject.flattenObject(queries);
|
|
249
264
|
}
|
|
250
265
|
if (animations) {
|
|
251
266
|
for(const animationName in animations){
|
|
@@ -261,31 +276,31 @@ class MasterCSS {
|
|
|
261
276
|
}
|
|
262
277
|
}
|
|
263
278
|
const flattedStyles = styles ? flattenObject.flattenObject(styles) : {};
|
|
264
|
-
const
|
|
265
|
-
const
|
|
266
|
-
if (Object.prototype.hasOwnProperty.call(this.styles,
|
|
267
|
-
const currentClass = this.styles[
|
|
268
|
-
const className = flattedStyles[
|
|
279
|
+
const utilityNames = Object.keys(flattedStyles);
|
|
280
|
+
const handleUtilityName = (utilityName)=>{
|
|
281
|
+
if (Object.prototype.hasOwnProperty.call(this.styles, utilityName)) return;
|
|
282
|
+
const currentClass = this.styles[utilityName] = [];
|
|
283
|
+
const className = flattedStyles[utilityName];
|
|
269
284
|
if (!className) return;
|
|
270
285
|
const classNames = className.replace(/(?:\n(?:\s*))+/g, ' ').trim().split(' ');
|
|
271
286
|
for (const eachClassName of classNames){
|
|
272
287
|
const handle = (className)=>{
|
|
273
288
|
if (Object.prototype.hasOwnProperty.call(this.stylesBy, className)) {
|
|
274
289
|
const currentRelation = this.stylesBy[className];
|
|
275
|
-
if (!currentRelation.includes(
|
|
276
|
-
currentRelation.push(
|
|
290
|
+
if (!currentRelation.includes(utilityName)) {
|
|
291
|
+
currentRelation.push(utilityName);
|
|
277
292
|
}
|
|
278
293
|
} else {
|
|
279
294
|
this.stylesBy[className] = [
|
|
280
|
-
|
|
295
|
+
utilityName
|
|
281
296
|
];
|
|
282
297
|
}
|
|
283
298
|
if (!currentClass.includes(className)) {
|
|
284
299
|
currentClass.push(className);
|
|
285
300
|
}
|
|
286
301
|
};
|
|
287
|
-
if (
|
|
288
|
-
|
|
302
|
+
if (utilityNames.includes(eachClassName)) {
|
|
303
|
+
handleUtilityName(eachClassName);
|
|
289
304
|
for (const parentClassName of this.styles[eachClassName]){
|
|
290
305
|
handle(parentClassName);
|
|
291
306
|
}
|
|
@@ -294,49 +309,54 @@ class MasterCSS {
|
|
|
294
309
|
}
|
|
295
310
|
}
|
|
296
311
|
};
|
|
297
|
-
for (const
|
|
298
|
-
|
|
312
|
+
for (const eachUtilityName of utilityNames){
|
|
313
|
+
handleUtilityName(eachUtilityName);
|
|
299
314
|
}
|
|
300
|
-
if (
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
+
if (rules || utilities) {
|
|
316
|
+
const rulesEntries = [];
|
|
317
|
+
if (utilities) {
|
|
318
|
+
for(const utilityName in utilities){
|
|
319
|
+
const declarations = utilities[utilityName];
|
|
320
|
+
rulesEntries.push([
|
|
321
|
+
utilityName,
|
|
322
|
+
{
|
|
323
|
+
declarations,
|
|
324
|
+
layer: layer.Utility
|
|
325
|
+
}
|
|
326
|
+
]);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
if (rules) {
|
|
330
|
+
rulesEntries.push(...Object.entries(rules));
|
|
331
|
+
}
|
|
332
|
+
const rulesEntriesLength = rulesEntries.length;
|
|
333
|
+
const colorNames = Object.keys(colorVariableNames);
|
|
334
|
+
rulesEntries.sort((a, b)=>{
|
|
315
335
|
if (a[1].layer !== b[1].layer) {
|
|
316
336
|
return (b[1].layer || 0) - (a[1].layer || 0);
|
|
317
337
|
}
|
|
318
338
|
return b[0].localeCompare(a[0]);
|
|
319
|
-
})
|
|
320
|
-
|
|
321
|
-
const colorNames = Object.keys(colorVariableNames);
|
|
322
|
-
rulesEntries.forEach(([id, eachRuleDefinition], index)=>{
|
|
323
|
-
const eachRegisteredRule = {
|
|
339
|
+
}).forEach(([id, eachRuleDefinition], index)=>{
|
|
340
|
+
const EachRule = {
|
|
324
341
|
id,
|
|
342
|
+
keys: [],
|
|
325
343
|
variables: {},
|
|
326
|
-
|
|
344
|
+
matchers: {},
|
|
345
|
+
order: rulesEntriesLength - 1 - index,
|
|
327
346
|
definition: eachRuleDefinition
|
|
328
347
|
};
|
|
329
|
-
this.
|
|
330
|
-
const
|
|
348
|
+
this.Rules.push(EachRule);
|
|
349
|
+
const { matcher, layer: layer$1, subkey, ambiguousKeys, ambiguousValues, sign } = eachRuleDefinition;
|
|
350
|
+
if (layer$1 === layer.Utility) {
|
|
351
|
+
EachRule.id = '.' + id;
|
|
352
|
+
EachRule.matchers.arbitrary = new RegExp('^' + escapeString(id) + '(?=!|\\*|>|\\+|~|:|\\[|@|_|\\.|$)', 'm');
|
|
353
|
+
}
|
|
331
354
|
// todo: 不可使用 startsWith 判斷,應改為更精準的從 config.variables 取得目標變數群組,但 config.variables 中的值還沒被 resolve 像是 Array
|
|
332
|
-
const addResolvedVariables = (
|
|
355
|
+
const addResolvedVariables = (groupName)=>{
|
|
333
356
|
for(const eachVariableName in this.variables){
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
...this.variables[eachVariableName],
|
|
338
|
-
name: eachVariableName
|
|
339
|
-
};
|
|
357
|
+
const eachVariable = this.variables[eachVariableName];
|
|
358
|
+
if (eachVariable.group === groupName) {
|
|
359
|
+
EachRule.variables[eachVariable.key] = eachVariable;
|
|
340
360
|
}
|
|
341
361
|
}
|
|
342
362
|
};
|
|
@@ -348,26 +368,49 @@ class MasterCSS {
|
|
|
348
368
|
}
|
|
349
369
|
// 2. custom `config.variables`
|
|
350
370
|
addResolvedVariables(id);
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
371
|
+
const keys = [];
|
|
372
|
+
let { key } = eachRuleDefinition;
|
|
373
|
+
if (layer$1 === layer.NativeShorthand || layer$1 === layer.Native) {
|
|
374
|
+
if (!key) eachRuleDefinition.key = key = id;
|
|
375
|
+
keys.push(id);
|
|
376
|
+
}
|
|
377
|
+
if (sign) {
|
|
378
|
+
EachRule.matchers.arbitrary = new RegExp(`^${sign}[^!*>+~:[@_]+\\|`);
|
|
379
|
+
} else if (!matcher) {
|
|
380
|
+
const colorsPatten = colorNames.join('|');
|
|
381
|
+
if (!key && !subkey) {
|
|
382
|
+
keys.push(id);
|
|
383
|
+
} else {
|
|
384
|
+
if (key && !keys.includes(key)) keys.push(key);
|
|
385
|
+
if (subkey) keys.push(subkey);
|
|
386
|
+
if (layer$1 === layer.Shorthand) {
|
|
387
|
+
keys.push(id);
|
|
360
388
|
}
|
|
361
|
-
|
|
362
|
-
|
|
389
|
+
}
|
|
390
|
+
if (ambiguousKeys?.length) {
|
|
391
|
+
const ambiguousKeyPattern = ambiguousKeys.length > 1 ? `(?:${ambiguousKeys.join('|')})` : ambiguousKeys[0];
|
|
392
|
+
const variableKeys = Object.keys(EachRule.variables);
|
|
393
|
+
if (ambiguousValues?.length) {
|
|
394
|
+
const ambiguousValuePatterns = [];
|
|
395
|
+
for (const eachAmbiguousValue of ambiguousValues){
|
|
396
|
+
if (eachAmbiguousValue instanceof RegExp) {
|
|
397
|
+
ambiguousValuePatterns.push(eachAmbiguousValue.source.replace('\\$colors', colorsPatten));
|
|
398
|
+
} else {
|
|
399
|
+
ambiguousValuePatterns.unshift(`${eachAmbiguousValue}(?:\\b|_)`);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
EachRule.matchers.value = new RegExp(`^${ambiguousKeyPattern}:(?:${ambiguousValuePatterns.join('|')})[^|]*?(?:@|$)`);
|
|
363
403
|
}
|
|
364
|
-
if (
|
|
365
|
-
|
|
404
|
+
if (variableKeys.length) {
|
|
405
|
+
EachRule.matchers.variable = new RegExp(`^${ambiguousKeyPattern}:(?:${variableKeys.join('|')}(?![a-zA-Z0-9-]))[^|]*?(?:@|$)`);
|
|
366
406
|
}
|
|
367
|
-
if (valueMatches.length) eachRegisteredRule.match = new RegExp(`^${key}:(?:${valueMatches.join('|')})[^|]*?(?:@|$)`);
|
|
368
|
-
} else {
|
|
369
|
-
eachRegisteredRule.match = match;
|
|
370
407
|
}
|
|
408
|
+
} else {
|
|
409
|
+
EachRule.matchers.arbitrary = matcher;
|
|
410
|
+
}
|
|
411
|
+
if (keys.length) {
|
|
412
|
+
EachRule.keys = keys;
|
|
413
|
+
EachRule.matchers.key = new RegExp(`^${keys.length > 1 ? `(${keys.join('|')})` : keys[0]}:`);
|
|
371
414
|
}
|
|
372
415
|
});
|
|
373
416
|
}
|
|
@@ -377,17 +420,29 @@ class MasterCSS {
|
|
|
377
420
|
* @param className
|
|
378
421
|
* @returns css text
|
|
379
422
|
*/ match(className) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
423
|
+
/**
|
|
424
|
+
* 1. variable
|
|
425
|
+
* @example fg:primary bg:blue
|
|
426
|
+
*/ for (const EachRule of this.Rules){
|
|
427
|
+
if (EachRule.matchers.variable?.test(className)) return EachRule;
|
|
385
428
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
429
|
+
/**
|
|
430
|
+
* 2. value (ambiguous.key * ambiguous.values)
|
|
431
|
+
* @example bg:current box:content font:12
|
|
432
|
+
*/ for (const EachRule of this.Rules){
|
|
433
|
+
if (EachRule.matchers.value?.test(className)) return EachRule;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* 3. full key
|
|
437
|
+
* @example text-align:center color:blue-40
|
|
438
|
+
*/ for (const EachRule of this.Rules){
|
|
439
|
+
if (EachRule.matchers.key?.test(className)) return EachRule;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* 4. arbitrary
|
|
443
|
+
* @example custom RegExp, utility
|
|
444
|
+
*/ for (const EachRule of this.Rules){
|
|
445
|
+
if (EachRule.matchers.arbitrary?.test(className)) return EachRule;
|
|
391
446
|
}
|
|
392
447
|
}
|
|
393
448
|
/**
|
|
@@ -405,20 +460,25 @@ class MasterCSS {
|
|
|
405
460
|
* @returns Rule
|
|
406
461
|
*/ create(syntax) {
|
|
407
462
|
if (Object.prototype.hasOwnProperty.call(this.ruleBy, syntax)) return this.ruleBy[syntax];
|
|
408
|
-
const
|
|
409
|
-
if (
|
|
410
|
-
return new rule.Rule(syntax,
|
|
463
|
+
const RegisteredRule = this.match(syntax);
|
|
464
|
+
if (RegisteredRule) {
|
|
465
|
+
return new rule.Rule(syntax, RegisteredRule, this);
|
|
411
466
|
}
|
|
412
467
|
}
|
|
413
468
|
/**
|
|
414
469
|
* 根據蒐集到的所有 DOM class 重新 create
|
|
415
|
-
*/ refresh(customConfig
|
|
470
|
+
*/ refresh(customConfig) {
|
|
471
|
+
if (customConfig) {
|
|
472
|
+
this.customConfig = customConfig;
|
|
473
|
+
} else {
|
|
474
|
+
customConfig = this.customConfig;
|
|
475
|
+
}
|
|
416
476
|
if (!customConfig?.override) {
|
|
417
477
|
// @ts-ignore
|
|
418
|
-
this.config = extendConfig
|
|
478
|
+
this.config = extendConfig(index.config, customConfig);
|
|
419
479
|
} else {
|
|
420
480
|
// @ts-ignore
|
|
421
|
-
this.config = extendConfig
|
|
481
|
+
this.config = extendConfig(customConfig);
|
|
422
482
|
}
|
|
423
483
|
this.resolve();
|
|
424
484
|
this.rules.length = 0;
|
|
@@ -495,15 +555,15 @@ class MasterCSS {
|
|
|
495
555
|
const variable = this.variables[eachVariableName];
|
|
496
556
|
if (!variable.usage) variable.usage = 0;
|
|
497
557
|
if (!--variable.usage) {
|
|
498
|
-
const removeProperty = (
|
|
499
|
-
const nativeRule = this.variablesNativeRules[
|
|
558
|
+
const removeProperty = (mode)=>{
|
|
559
|
+
const nativeRule = this.variablesNativeRules[mode];
|
|
500
560
|
nativeRule.cssRule.style.removeProperty('--' + eachVariableName);
|
|
501
561
|
if (!nativeRule.cssRule.style.length) {
|
|
502
562
|
const variablesRule = this.rules[0];
|
|
503
563
|
const index = variablesRule.natives.indexOf(nativeRule);
|
|
504
564
|
sheet?.deleteRule(index);
|
|
505
565
|
variablesRule.natives.splice(index, 1);
|
|
506
|
-
delete this.variablesNativeRules[
|
|
566
|
+
delete this.variablesNativeRules[mode];
|
|
507
567
|
if (!variablesRule.natives.length) {
|
|
508
568
|
this.rules.splice(0, 1);
|
|
509
569
|
this.variablesNativeRules = {};
|
|
@@ -513,9 +573,9 @@ class MasterCSS {
|
|
|
513
573
|
if (variable.value) {
|
|
514
574
|
removeProperty('');
|
|
515
575
|
}
|
|
516
|
-
if (variable.
|
|
517
|
-
for(const
|
|
518
|
-
removeProperty(
|
|
576
|
+
if (variable.modes) {
|
|
577
|
+
for(const mode in variable.modes){
|
|
578
|
+
removeProperty(mode);
|
|
519
579
|
}
|
|
520
580
|
}
|
|
521
581
|
}
|
|
@@ -530,7 +590,7 @@ class MasterCSS {
|
|
|
530
590
|
if (!keyframe.usage) keyframe.usage = 0;
|
|
531
591
|
if (!--keyframe.usage && keyframe.native) {
|
|
532
592
|
const nativeIndex = keyframeRule.natives.indexOf(keyframe.native);
|
|
533
|
-
|
|
593
|
+
sheet?.deleteRule(Object.keys(this.variablesNativeRules).length + nativeIndex);
|
|
534
594
|
keyframeRule.natives.splice(nativeIndex, 1);
|
|
535
595
|
keyframe.native = undefined;
|
|
536
596
|
}
|
|
@@ -578,7 +638,7 @@ class MasterCSS {
|
|
|
578
638
|
* @example <1 <2 <3 ALL >=1 >=2 >=3
|
|
579
639
|
* @description
|
|
580
640
|
*/ const endIndex = this.rules.length - 1;
|
|
581
|
-
const {
|
|
641
|
+
const { at, atToken, order, priority, hasWhere, className } = rule;
|
|
582
642
|
const findIndex = (startIndex, stopCheck, matchCheck)=>{
|
|
583
643
|
let i = startIndex;
|
|
584
644
|
for(; i <= endIndex; i++){
|
|
@@ -590,14 +650,15 @@ class MasterCSS {
|
|
|
590
650
|
};
|
|
591
651
|
let matchStartIndex;
|
|
592
652
|
let matchEndIndex;
|
|
593
|
-
if (
|
|
594
|
-
const mediaStartIndex = this.rules.findIndex((eachRule)=>eachRule.media);
|
|
653
|
+
if (atToken) {
|
|
654
|
+
const mediaStartIndex = this.rules.findIndex((eachRule)=>eachRule.at?.media);
|
|
595
655
|
if (mediaStartIndex === -1) {
|
|
596
656
|
index = endIndex + 1;
|
|
597
657
|
} else {
|
|
598
|
-
const {
|
|
658
|
+
const maxWidthFeature = at.media?.find(({ name })=>name === 'max-width');
|
|
659
|
+
const minWidthFeature = at.media?.find(({ name })=>name === 'min-width');
|
|
599
660
|
if (maxWidthFeature || minWidthFeature) {
|
|
600
|
-
const mediaWidthStartIndex = this.rules.findIndex((eachRule)=>eachRule.media?.
|
|
661
|
+
const mediaWidthStartIndex = this.rules.findIndex((eachRule)=>eachRule.at?.media?.find(({ name })=>name === 'max-width' || name === 'min-width'));
|
|
601
662
|
if (mediaWidthStartIndex === -1) {
|
|
602
663
|
index = endIndex + 1;
|
|
603
664
|
} else {
|
|
@@ -608,10 +669,10 @@ class MasterCSS {
|
|
|
608
669
|
* find 第一個所遇到同樣 feature 且範圍值比自己大的 rule,
|
|
609
670
|
* 並插入在該 rule 之後,讓自己優先被套用
|
|
610
671
|
*/ if (priority === -1) {
|
|
611
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.priority !== -1, (eachRule)=>eachRule.media
|
|
672
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.priority !== -1, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width'));
|
|
612
673
|
matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.priority !== -1);
|
|
613
674
|
} else {
|
|
614
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, undefined, (eachRule)=>eachRule.media
|
|
675
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, undefined, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1);
|
|
615
676
|
matchEndIndex = endIndex;
|
|
616
677
|
}
|
|
617
678
|
if (matchStartIndex !== -1) {
|
|
@@ -620,7 +681,9 @@ class MasterCSS {
|
|
|
620
681
|
const endI = matchStartIndex;
|
|
621
682
|
matchStartIndex = undefined;
|
|
622
683
|
for(; i >= endI; i--){
|
|
623
|
-
const
|
|
684
|
+
const eachRule = this.rules[i];
|
|
685
|
+
const eachMaxWidthFeature = eachRule.at.media?.find(({ name })=>name === 'max-width');
|
|
686
|
+
const eachMinWidthFeature = eachRule.at.media?.find(({ name })=>name === 'min-width');
|
|
624
687
|
const eachRange = eachMaxWidthFeature.value - eachMinWidthFeature.value;
|
|
625
688
|
if (eachRange < range) {
|
|
626
689
|
matchEndIndex = i - 1;
|
|
@@ -634,7 +697,9 @@ class MasterCSS {
|
|
|
634
697
|
if (matchStartIndex !== -1 && matchStartIndex !== undefined) {
|
|
635
698
|
const range = maxWidthFeature.value - minWidthFeature.value;
|
|
636
699
|
for(let i = matchEndIndex; i >= matchStartIndex; i--){
|
|
637
|
-
const
|
|
700
|
+
const eachRule = this.rules[i];
|
|
701
|
+
const eachMaxWidthFeature = eachRule.at.media?.find(({ name })=>name === 'max-width');
|
|
702
|
+
const eachMinWidthFeature = eachRule.at.media?.find(({ name })=>name === 'min-width');
|
|
638
703
|
const eachRange = eachMaxWidthFeature.value - eachMinWidthFeature.value;
|
|
639
704
|
if (eachRange < range) {
|
|
640
705
|
matchEndIndex = i - 1;
|
|
@@ -649,15 +714,15 @@ class MasterCSS {
|
|
|
649
714
|
* find 第一個所遇到同樣 feature 且值比自己大的 rule,
|
|
650
715
|
* 並插入在該 rule 之後,讓自己優先被套用
|
|
651
716
|
*/ if (priority === -1) {
|
|
652
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media
|
|
653
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media
|
|
717
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') || eachRule.priority !== -1, (eachRule)=>!eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width'));
|
|
718
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') || eachRule.priority !== -1);
|
|
654
719
|
} else {
|
|
655
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media
|
|
656
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media
|
|
720
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1, (eachRule)=>!eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1);
|
|
721
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1);
|
|
657
722
|
}
|
|
658
723
|
if (matchStartIndex !== -1) {
|
|
659
724
|
for(let i = matchEndIndex; i >= matchStartIndex; i--){
|
|
660
|
-
const value = this.rules[i].media
|
|
725
|
+
const value = (this.rules[i].at.media?.find(({ name })=>name === 'min-width')).value;
|
|
661
726
|
if (value > minWidthFeature.value) {
|
|
662
727
|
matchEndIndex = i - 1;
|
|
663
728
|
} else if (value < minWidthFeature.value) {
|
|
@@ -671,15 +736,15 @@ class MasterCSS {
|
|
|
671
736
|
* find 第一個所遇到同樣 feature 且值比自己大的 rule,
|
|
672
737
|
* 並插入在該 rule 之後,讓自己優先被套用
|
|
673
738
|
*/ if (priority === -1) {
|
|
674
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media
|
|
675
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media
|
|
739
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'min-width') || eachRule.priority !== -1, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width'));
|
|
740
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'min-width') || eachRule.priority !== -1);
|
|
676
741
|
} else {
|
|
677
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media
|
|
678
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media
|
|
742
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.priority !== -1);
|
|
743
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1);
|
|
679
744
|
}
|
|
680
745
|
if (matchStartIndex !== -1) {
|
|
681
746
|
for(let i = matchEndIndex; i >= matchStartIndex; i--){
|
|
682
|
-
const value = this.rules[i].media
|
|
747
|
+
const value = (this.rules[i].at.media?.find(({ name })=>name === 'max-width')).value;
|
|
683
748
|
if (value < maxWidthFeature.value) {
|
|
684
749
|
matchEndIndex = i - 1;
|
|
685
750
|
} else if (value > maxWidthFeature.value) {
|
|
@@ -693,10 +758,10 @@ class MasterCSS {
|
|
|
693
758
|
} else {
|
|
694
759
|
if (priority === -1) {
|
|
695
760
|
matchStartIndex = mediaStartIndex;
|
|
696
|
-
matchEndIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.media?.
|
|
761
|
+
matchEndIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width') || eachRule.priority !== -1);
|
|
697
762
|
} else {
|
|
698
|
-
matchStartIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.media?.
|
|
699
|
-
matchEndIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.media?.
|
|
763
|
+
matchStartIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width'), (eachRule)=>eachRule.priority !== -1);
|
|
764
|
+
matchEndIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width'));
|
|
700
765
|
}
|
|
701
766
|
}
|
|
702
767
|
}
|
|
@@ -704,10 +769,10 @@ class MasterCSS {
|
|
|
704
769
|
const findStartIndex = Object.keys(this.variablesNativeRules).length ? this.hasKeyframesRule ? 2 : 1 : this.hasKeyframesRule ? 1 : 0;
|
|
705
770
|
if (priority === -1) {
|
|
706
771
|
matchStartIndex = findStartIndex;
|
|
707
|
-
matchEndIndex = findIndex(findStartIndex, (eachRule)=>eachRule.
|
|
772
|
+
matchEndIndex = findIndex(findStartIndex, (eachRule)=>eachRule.atToken || eachRule.priority !== -1);
|
|
708
773
|
} else {
|
|
709
|
-
matchStartIndex = findIndex(findStartIndex, (eachRule)=>eachRule.
|
|
710
|
-
matchEndIndex = findIndex(findStartIndex, (eachRule)=>eachRule.
|
|
774
|
+
matchStartIndex = findIndex(findStartIndex, (eachRule)=>eachRule.atToken, (eachRule)=>eachRule.priority !== -1);
|
|
775
|
+
matchEndIndex = findIndex(findStartIndex, (eachRule)=>eachRule.atToken);
|
|
711
776
|
}
|
|
712
777
|
}
|
|
713
778
|
if (index === undefined && matchEndIndex !== undefined && matchStartIndex !== undefined) {
|
|
@@ -751,7 +816,6 @@ class MasterCSS {
|
|
|
751
816
|
}
|
|
752
817
|
this.rules.splice(index, 0, rule);
|
|
753
818
|
this.ruleBy[className] = rule;
|
|
754
|
-
// 只在瀏覽器端運行
|
|
755
819
|
if (this.style) {
|
|
756
820
|
const sheet = this.style.sheet;
|
|
757
821
|
let cssRuleIndex = 0;
|
|
@@ -787,6 +851,7 @@ class MasterCSS {
|
|
|
787
851
|
// animations
|
|
788
852
|
this.handleRuleWithAnimationNames(rule);
|
|
789
853
|
rule.definition.insert?.call(rule);
|
|
854
|
+
return index;
|
|
790
855
|
}
|
|
791
856
|
get text() {
|
|
792
857
|
return this.rules.map((eachRule)=>eachRule.text).join('');
|
|
@@ -850,23 +915,23 @@ class MasterCSS {
|
|
|
850
915
|
if (variable.usage) {
|
|
851
916
|
variable.usage++;
|
|
852
917
|
} else {
|
|
853
|
-
const addProperty = (
|
|
854
|
-
let nativeRule = this.variablesNativeRules[
|
|
918
|
+
const addProperty = (mode, variable)=>{
|
|
919
|
+
let nativeRule = this.variablesNativeRules[mode];
|
|
855
920
|
if (!nativeRule) {
|
|
856
921
|
let cssRule;
|
|
857
922
|
let mediaConditionText;
|
|
858
923
|
let selectorText;
|
|
859
|
-
if (
|
|
860
|
-
switch(this.config.
|
|
924
|
+
if (mode) {
|
|
925
|
+
switch(this.config.modeDriver){
|
|
861
926
|
case 'media':
|
|
862
|
-
mediaConditionText = `@media(prefers-color-scheme:${
|
|
927
|
+
mediaConditionText = `@media(prefers-color-scheme:${mode})`;
|
|
863
928
|
selectorText = ':root';
|
|
864
929
|
break;
|
|
865
930
|
case 'host':
|
|
866
|
-
selectorText = `:host(.${
|
|
931
|
+
selectorText = `:host(.${mode})`;
|
|
867
932
|
break;
|
|
868
933
|
default:
|
|
869
|
-
selectorText = `.${
|
|
934
|
+
selectorText = `.${mode}`;
|
|
870
935
|
break;
|
|
871
936
|
}
|
|
872
937
|
} else {
|
|
@@ -916,19 +981,19 @@ class MasterCSS {
|
|
|
916
981
|
};
|
|
917
982
|
}
|
|
918
983
|
}
|
|
919
|
-
nativeRule = this.pushVariableNativeRule(
|
|
984
|
+
nativeRule = this.pushVariableNativeRule(mode, cssRule);
|
|
920
985
|
}
|
|
921
986
|
const propertyName = '--' + eachVariableName;
|
|
922
987
|
if (!initializing || !nativeRule.cssRule.style.getPropertyValue(propertyName)) {
|
|
923
|
-
nativeRule.cssRule.style.setProperty(propertyName, String(
|
|
988
|
+
nativeRule.cssRule.style.setProperty(propertyName, String(variable.value));
|
|
924
989
|
}
|
|
925
990
|
};
|
|
926
991
|
if (variable.value) {
|
|
927
992
|
addProperty('', variable);
|
|
928
993
|
}
|
|
929
|
-
if (variable.
|
|
930
|
-
for(const
|
|
931
|
-
addProperty(
|
|
994
|
+
if (variable.modes) {
|
|
995
|
+
for(const mode in variable.modes){
|
|
996
|
+
addProperty(mode, variable.modes[mode]);
|
|
932
997
|
}
|
|
933
998
|
}
|
|
934
999
|
variable.usage = 1;
|
|
@@ -936,7 +1001,7 @@ class MasterCSS {
|
|
|
936
1001
|
}
|
|
937
1002
|
}
|
|
938
1003
|
}
|
|
939
|
-
pushVariableNativeRule(
|
|
1004
|
+
pushVariableNativeRule(mode, variableCSSRule) {
|
|
940
1005
|
if (!Object.keys(this.variablesNativeRules).length) {
|
|
941
1006
|
this.variablesNativeRules = {};
|
|
942
1007
|
const newRule = {
|
|
@@ -965,7 +1030,7 @@ class MasterCSS {
|
|
|
965
1030
|
return prefix + properties.join(';') + suffix;
|
|
966
1031
|
}
|
|
967
1032
|
};
|
|
968
|
-
this.rules[0].natives.push(this.variablesNativeRules[
|
|
1033
|
+
this.rules[0].natives.push(this.variablesNativeRules[mode] = nativeRule);
|
|
969
1034
|
return nativeRule;
|
|
970
1035
|
}
|
|
971
1036
|
}
|