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