@master/css 2.0.0-rc.26 → 2.0.0-rc.28
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 +6 -5
- package/dist/config/index.d.ts +13 -11
- package/dist/config/index.mjs +6 -5
- package/dist/config/modes.cjs +8 -0
- package/dist/config/modes.d.ts +3 -0
- package/dist/config/modes.mjs +6 -0
- package/dist/config/queries.cjs +4 -0
- package/dist/config/queries.d.ts +4 -0
- package/dist/config/queries.mjs +4 -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/core.cjs +193 -133
- package/dist/core.d.ts +18 -14
- package/dist/core.mjs +194 -134
- package/dist/index.cjs +36 -16
- package/dist/index.d.ts +13 -8
- package/dist/index.mjs +14 -11
- package/dist/layer.cjs +25 -20
- package/dist/layer.d.ts +26 -9
- package/dist/layer.mjs +22 -19
- package/dist/rule.cjs +46 -52
- package/dist/rule.d.ts +37 -24
- package/dist/rule.mjs +46 -52
- 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 +5 -11
- package/dist/{functions → utils}/reorder-for-readable-classes.d.ts +1 -5
- package/dist/{functions → utils}/reorder-for-readable-classes.mjs +6 -12
- package/package.json +1 -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/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/{functions → utils}/are-rule-modes-equal.cjs +0 -0
- /package/dist/{functions → utils}/are-rule-modes-equal.d.ts +0 -0
- /package/dist/{functions → utils}/are-rule-modes-equal.mjs +0 -0
- /package/dist/{functions → utils}/are-rule-queries-equal.cjs +0 -0
- /package/dist/{functions → utils}/are-rule-queries-equal.d.ts +0 -0
- /package/dist/{functions → utils}/are-rule-queries-equal.mjs +0 -0
- /package/dist/{functions → utils}/are-rule-selectors-equal.cjs +0 -0
- /package/dist/{functions → utils}/are-rule-selectors-equal.d.ts +0 -0
- /package/dist/{functions → utils}/are-rule-selectors-equal.mjs +0 -0
- /package/dist/{functions → utils}/are-rule-states-equal.cjs +0 -0
- /package/dist/{functions → utils}/are-rule-states-equal.d.ts +0 -0
- /package/dist/{functions → utils}/are-rule-states-equal.mjs +0 -0
- /package/dist/{functions → utils}/are-rules-duplicated.cjs +0 -0
- /package/dist/{functions → utils}/are-rules-duplicated.d.ts +0 -0
- /package/dist/{functions → utils}/are-rules-duplicated.mjs +0 -0
- /package/dist/{functions → utils}/extend-config.cjs +0 -0
- /package/dist/{functions → utils}/extend-config.d.ts +0 -0
- /package/dist/{functions → utils}/extend-config.mjs +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const utilities = {
|
|
4
4
|
square: {
|
|
5
5
|
'aspect-ratio': '1/1'
|
|
6
6
|
},
|
|
@@ -16,9 +16,6 @@ const semantics = {
|
|
|
16
16
|
hidden: {
|
|
17
17
|
display: 'none'
|
|
18
18
|
},
|
|
19
|
-
hide: {
|
|
20
|
-
display: 'none'
|
|
21
|
-
},
|
|
22
19
|
block: {
|
|
23
20
|
display: 'block'
|
|
24
21
|
},
|
|
@@ -191,4 +188,4 @@ const semantics = {
|
|
|
191
188
|
}
|
|
192
189
|
};
|
|
193
190
|
|
|
194
|
-
module.exports =
|
|
191
|
+
module.exports = utilities;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const
|
|
1
|
+
declare const utilities: {
|
|
2
2
|
readonly square: {
|
|
3
3
|
readonly 'aspect-ratio': "1/1";
|
|
4
4
|
};
|
|
@@ -14,9 +14,6 @@ declare const semantics: {
|
|
|
14
14
|
readonly hidden: {
|
|
15
15
|
readonly display: "none";
|
|
16
16
|
};
|
|
17
|
-
readonly hide: {
|
|
18
|
-
readonly display: "none";
|
|
19
|
-
};
|
|
20
17
|
readonly block: {
|
|
21
18
|
readonly display: "block";
|
|
22
19
|
};
|
|
@@ -188,4 +185,4 @@ declare const semantics: {
|
|
|
188
185
|
readonly height: "fit-content";
|
|
189
186
|
};
|
|
190
187
|
};
|
|
191
|
-
export default
|
|
188
|
+
export default utilities;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const utilities = {
|
|
2
2
|
square: {
|
|
3
3
|
'aspect-ratio': '1/1'
|
|
4
4
|
},
|
|
@@ -14,9 +14,6 @@ const semantics = {
|
|
|
14
14
|
hidden: {
|
|
15
15
|
display: 'none'
|
|
16
16
|
},
|
|
17
|
-
hide: {
|
|
18
|
-
display: 'none'
|
|
19
|
-
},
|
|
20
17
|
block: {
|
|
21
18
|
display: 'block'
|
|
22
19
|
},
|
|
@@ -189,4 +186,4 @@ const semantics = {
|
|
|
189
186
|
}
|
|
190
187
|
};
|
|
191
188
|
|
|
192
|
-
export {
|
|
189
|
+
export { utilities as default };
|
package/dist/core.cjs
CHANGED
|
@@ -7,7 +7,7 @@ var index = require('./config/index.cjs');
|
|
|
7
7
|
var layer = require('./layer.cjs');
|
|
8
8
|
var hexToRgb = require('./utils/hex-to-rgb.cjs');
|
|
9
9
|
var flattenObject = require('./utils/flatten-object.cjs');
|
|
10
|
-
var extendConfig = require('./
|
|
10
|
+
var extendConfig = require('./utils/extend-config.cjs');
|
|
11
11
|
|
|
12
12
|
class MasterCSS {
|
|
13
13
|
customConfig;
|
|
@@ -16,15 +16,13 @@ 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
27
|
this.config = extendConfig(index.config, customConfig);
|
|
30
28
|
} else {
|
|
@@ -42,8 +40,7 @@ class MasterCSS {
|
|
|
42
40
|
this.variables = {};
|
|
43
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,89 +79,104 @@ 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
102
|
const currentMode = replacedMode ?? mode;
|
|
100
103
|
if (currentMode !== undefined) {
|
|
101
|
-
if (Object.prototype.hasOwnProperty.call(this.variables,
|
|
102
|
-
const
|
|
104
|
+
if (Object.prototype.hasOwnProperty.call(this.variables, flatName)) {
|
|
105
|
+
const foundVariable = this.variables[flatName];
|
|
103
106
|
if (currentMode) {
|
|
104
|
-
if (!
|
|
105
|
-
|
|
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
118
|
if (currentMode) {
|
|
116
119
|
const newVariable = {
|
|
117
|
-
|
|
120
|
+
key: variable.key,
|
|
121
|
+
name: variable.name,
|
|
122
|
+
group: variable.group,
|
|
123
|
+
type: variable.type,
|
|
118
124
|
modes: {
|
|
119
|
-
[currentMode]:
|
|
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[
|
|
178
|
+
unexecutedAliasVariable[flatName][mode] = ()=>{
|
|
179
|
+
delete unexecutedAliasVariable[flatName][mode];
|
|
168
180
|
const [alias, aliasMode] = aliasResult[1].split('@');
|
|
169
181
|
if (alias) {
|
|
170
182
|
if (Object.prototype.hasOwnProperty.call(unexecutedAliasVariable, alias)) {
|
|
@@ -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,8 +248,11 @@ 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
257
|
for (const mode of Object.keys(unexecutedAliasVariable[name])){
|
|
243
258
|
unexecutedAliasVariable[name][mode]?.();
|
|
@@ -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,14 +460,19 @@ 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
478
|
this.config = extendConfig(index.config, customConfig);
|
|
@@ -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
|
}
|
|
@@ -756,7 +816,6 @@ class MasterCSS {
|
|
|
756
816
|
}
|
|
757
817
|
this.rules.splice(index, 0, rule);
|
|
758
818
|
this.ruleBy[className] = rule;
|
|
759
|
-
// 只在瀏覽器端運行
|
|
760
819
|
if (this.style) {
|
|
761
820
|
const sheet = this.style.sheet;
|
|
762
821
|
let cssRuleIndex = 0;
|
|
@@ -792,6 +851,7 @@ class MasterCSS {
|
|
|
792
851
|
// animations
|
|
793
852
|
this.handleRuleWithAnimationNames(rule);
|
|
794
853
|
rule.definition.insert?.call(rule);
|
|
854
|
+
return index;
|
|
795
855
|
}
|
|
796
856
|
get text() {
|
|
797
857
|
return this.rules.map((eachRule)=>eachRule.text).join('');
|
|
@@ -855,14 +915,14 @@ class MasterCSS {
|
|
|
855
915
|
if (variable.usage) {
|
|
856
916
|
variable.usage++;
|
|
857
917
|
} else {
|
|
858
|
-
const addProperty = (mode,
|
|
918
|
+
const addProperty = (mode, variable)=>{
|
|
859
919
|
let nativeRule = this.variablesNativeRules[mode];
|
|
860
920
|
if (!nativeRule) {
|
|
861
921
|
let cssRule;
|
|
862
922
|
let mediaConditionText;
|
|
863
923
|
let selectorText;
|
|
864
924
|
if (mode) {
|
|
865
|
-
switch(this.config.
|
|
925
|
+
switch(this.config.modes?.[mode]){
|
|
866
926
|
case 'media':
|
|
867
927
|
mediaConditionText = `@media(prefers-color-scheme:${mode})`;
|
|
868
928
|
selectorText = ':root';
|
|
@@ -925,7 +985,7 @@ class MasterCSS {
|
|
|
925
985
|
}
|
|
926
986
|
const propertyName = '--' + eachVariableName;
|
|
927
987
|
if (!initializing || !nativeRule.cssRule.style.getPropertyValue(propertyName)) {
|
|
928
|
-
nativeRule.cssRule.style.setProperty(propertyName, String(
|
|
988
|
+
nativeRule.cssRule.style.setProperty(propertyName, String(variable.value));
|
|
929
989
|
}
|
|
930
990
|
};
|
|
931
991
|
if (variable.value) {
|