@master/css 2.0.0-rc.40 → 2.0.0-rc.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/index.cjs +3 -3
- package/dist/config/index.d.ts +8 -8
- package/dist/config/index.mjs +3 -3
- package/dist/config/{rules.cjs → syntaxes.cjs} +5 -5
- package/dist/config/syntaxes.d.ts +282 -0
- package/dist/config/{rules.mjs → syntaxes.mjs} +5 -5
- package/dist/config/utilities.cjs +2 -1
- package/dist/config/utilities.d.ts +1 -0
- package/dist/config/utilities.mjs +2 -1
- package/dist/config/variables.cjs +213 -3
- package/dist/config/variables.d.ts +1 -505
- package/dist/config/variables.mjs +213 -3
- package/dist/core.cjs +66 -66
- package/dist/core.d.ts +2 -2
- package/dist/core.mjs +66 -66
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +2 -2
- package/dist/polyfills/css-escape2.cjs +1 -1
- package/dist/polyfills/css-escape2.mjs +1 -1
- package/dist/rule.cjs +1 -1
- package/dist/rule.d.ts +2 -2
- package/dist/rule.mjs +1 -1
- package/dist/utils/autofill-solid-style.d.ts +2 -2
- package/dist/utils/extend-config.cjs +1 -0
- package/dist/utils/extend-config.mjs +1 -0
- package/dist/utils/is-core-rule.cjs +2 -2
- package/dist/utils/is-core-rule.mjs +2 -2
- package/dist/utils/reorder-for-readable-classes.cjs +1 -1
- package/dist/utils/reorder-for-readable-classes.mjs +1 -1
- package/package.json +1 -1
- package/dist/config/rules.d.ts +0 -282
- /package/dist/utils/{are-rules-duplicated.cjs → are-syntaxes-duplicated.cjs} +0 -0
- /package/dist/utils/{are-rules-duplicated.d.ts → are-syntaxes-duplicated.d.ts} +0 -0
- /package/dist/utils/{are-rules-duplicated.mjs → are-syntaxes-duplicated.mjs} +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import colors from '@master/colors';
|
|
2
|
+
import extend from '@techor/extend';
|
|
2
3
|
|
|
3
|
-
const variables = {
|
|
4
|
+
const variables = extend(colors, {
|
|
4
5
|
full: '100%',
|
|
5
6
|
fit: 'fit-content',
|
|
6
7
|
max: 'max-content',
|
|
@@ -119,7 +120,216 @@ const variables = {
|
|
|
119
120
|
view: 'view-box'
|
|
120
121
|
},
|
|
121
122
|
current: 'currentColor',
|
|
122
|
-
|
|
123
|
-
|
|
123
|
+
white: '#ffffff',
|
|
124
|
+
black: '#000000',
|
|
125
|
+
base: {
|
|
126
|
+
'@light': '$(white)',
|
|
127
|
+
'@dark': '$(gray-95)'
|
|
128
|
+
},
|
|
129
|
+
canvas: {
|
|
130
|
+
'@light': '$(slate-5)',
|
|
131
|
+
'@dark': '$(gray-90)'
|
|
132
|
+
},
|
|
133
|
+
surface: {
|
|
134
|
+
'@light': '$(white)',
|
|
135
|
+
'@dark': '$(gray-80)'
|
|
136
|
+
},
|
|
137
|
+
invert: {
|
|
138
|
+
'@light': '$(black)',
|
|
139
|
+
'@dark': '$(white)'
|
|
140
|
+
},
|
|
141
|
+
line: {
|
|
142
|
+
neutral: {
|
|
143
|
+
'@light': '$(slate-60)',
|
|
144
|
+
'@dark': '$(gray-30)'
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
gray: {
|
|
148
|
+
'@light': '$(gray-30)',
|
|
149
|
+
'@dark': '$(gray-40)'
|
|
150
|
+
},
|
|
151
|
+
slate: {
|
|
152
|
+
'@light': '$(slate-30)',
|
|
153
|
+
'@dark': '$(slate-40)'
|
|
154
|
+
},
|
|
155
|
+
brown: {
|
|
156
|
+
'@light': '$(brown-40)',
|
|
157
|
+
'@dark': '$(brown-50)'
|
|
158
|
+
},
|
|
159
|
+
orange: {
|
|
160
|
+
'@light': '$(orange-40)',
|
|
161
|
+
'@dark': '$(orange-50)'
|
|
162
|
+
},
|
|
163
|
+
amber: {
|
|
164
|
+
'@light': '$(amber-40)',
|
|
165
|
+
'@dark': '$(amber-50)'
|
|
166
|
+
},
|
|
167
|
+
yellow: {
|
|
168
|
+
'@light': '$(yellow-40)',
|
|
169
|
+
'@dark': '$(yellow-50)'
|
|
170
|
+
},
|
|
171
|
+
lime: {
|
|
172
|
+
'@light': '$(lime-40)',
|
|
173
|
+
'@dark': '$(lime-50)'
|
|
174
|
+
},
|
|
175
|
+
green: {
|
|
176
|
+
'@light': '$(green-40)',
|
|
177
|
+
'@dark': '$(green-50)'
|
|
178
|
+
},
|
|
179
|
+
beryl: {
|
|
180
|
+
'@light': '$(beryl-40)',
|
|
181
|
+
'@dark': '$(beryl-50)'
|
|
182
|
+
},
|
|
183
|
+
teal: {
|
|
184
|
+
'@light': '$(teal-40)',
|
|
185
|
+
'@dark': '$(teal-50)'
|
|
186
|
+
},
|
|
187
|
+
cyan: {
|
|
188
|
+
'@light': '$(cyan-40)',
|
|
189
|
+
'@dark': '$(cyan-50)'
|
|
190
|
+
},
|
|
191
|
+
sky: {
|
|
192
|
+
'@light': '$(sky-60)',
|
|
193
|
+
'@dark': '$(sky-50)'
|
|
194
|
+
},
|
|
195
|
+
blue: {
|
|
196
|
+
'@light': '$(blue-60)',
|
|
197
|
+
'@dark': '$(blue-50)'
|
|
198
|
+
},
|
|
199
|
+
indigo: {
|
|
200
|
+
'@light': '$(indigo-60)',
|
|
201
|
+
'@dark': '$(indigo-50)'
|
|
202
|
+
},
|
|
203
|
+
violet: {
|
|
204
|
+
'@light': '$(violet-60)',
|
|
205
|
+
'@dark': '$(violet-50)'
|
|
206
|
+
},
|
|
207
|
+
purple: {
|
|
208
|
+
'@light': '$(purple-60)',
|
|
209
|
+
'@dark': '$(purple-50)'
|
|
210
|
+
},
|
|
211
|
+
fuchsia: {
|
|
212
|
+
'@light': '$(fuchsia-60)',
|
|
213
|
+
'@dark': '$(fuchsia-50)'
|
|
214
|
+
},
|
|
215
|
+
pink: {
|
|
216
|
+
'@light': '$(pink-60)',
|
|
217
|
+
'@dark': '$(pink-50)'
|
|
218
|
+
},
|
|
219
|
+
crimson: {
|
|
220
|
+
'@light': '$(crimson-60)',
|
|
221
|
+
'@dark': '$(crimson-50)'
|
|
222
|
+
},
|
|
223
|
+
red: {
|
|
224
|
+
'@light': '$(red-60)',
|
|
225
|
+
'@dark': '$(red-50)'
|
|
226
|
+
},
|
|
227
|
+
text: {
|
|
228
|
+
invert: {
|
|
229
|
+
'@light': '$(black)',
|
|
230
|
+
'@dark': '$(white)'
|
|
231
|
+
},
|
|
232
|
+
strong: {
|
|
233
|
+
'@light': '$(slate-95)',
|
|
234
|
+
'@dark': '$(gray-10)'
|
|
235
|
+
},
|
|
236
|
+
neutral: {
|
|
237
|
+
'@light': '$(slate-70)',
|
|
238
|
+
'@dark': '$(gray-30)'
|
|
239
|
+
},
|
|
240
|
+
lightest: {
|
|
241
|
+
'@light': '$(slate-30)',
|
|
242
|
+
'@dark': '$(gray-60)'
|
|
243
|
+
},
|
|
244
|
+
lighter: {
|
|
245
|
+
'@light': '$(slate-40)',
|
|
246
|
+
'@dark': '$(gray-50)'
|
|
247
|
+
},
|
|
248
|
+
light: {
|
|
249
|
+
'@light': '$(slate-50)',
|
|
250
|
+
'@dark': '$(gray-40)'
|
|
251
|
+
},
|
|
252
|
+
gray: {
|
|
253
|
+
'@light': '$(gray-60)',
|
|
254
|
+
'@dark': '$(gray-30)'
|
|
255
|
+
},
|
|
256
|
+
slate: {
|
|
257
|
+
'@light': '$(slate-60)',
|
|
258
|
+
'@dark': '$(slate-30)'
|
|
259
|
+
},
|
|
260
|
+
brown: {
|
|
261
|
+
'@light': '$(brown-60)',
|
|
262
|
+
'@dark': '$(brown-30)'
|
|
263
|
+
},
|
|
264
|
+
orange: {
|
|
265
|
+
'@light': '$(orange-60)',
|
|
266
|
+
'@dark': '$(orange-30)'
|
|
267
|
+
},
|
|
268
|
+
amber: {
|
|
269
|
+
'@light': '$(amber-60)',
|
|
270
|
+
'@dark': '$(amber-40)'
|
|
271
|
+
},
|
|
272
|
+
yellow: {
|
|
273
|
+
'@light': '$(yellow-60)',
|
|
274
|
+
'@dark': '$(yellow-40)'
|
|
275
|
+
},
|
|
276
|
+
lime: {
|
|
277
|
+
'@light': '$(lime-70)',
|
|
278
|
+
'@dark': '$(lime-40)'
|
|
279
|
+
},
|
|
280
|
+
green: {
|
|
281
|
+
'@light': '$(green-70)',
|
|
282
|
+
'@dark': '$(green-40)'
|
|
283
|
+
},
|
|
284
|
+
beryl: {
|
|
285
|
+
'@light': '$(beryl-70)',
|
|
286
|
+
'@dark': '$(beryl-40)'
|
|
287
|
+
},
|
|
288
|
+
teal: {
|
|
289
|
+
'@light': '$(teal-70)',
|
|
290
|
+
'@dark': '$(teal-40)'
|
|
291
|
+
},
|
|
292
|
+
cyan: {
|
|
293
|
+
'@light': '$(cyan-70)',
|
|
294
|
+
'@dark': '$(cyan-40)'
|
|
295
|
+
},
|
|
296
|
+
sky: {
|
|
297
|
+
'@light': '$(sky-70)',
|
|
298
|
+
'@dark': '$(sky-30)'
|
|
299
|
+
},
|
|
300
|
+
blue: {
|
|
301
|
+
'@light': '$(blue-60)',
|
|
302
|
+
'@dark': '$(blue-30)'
|
|
303
|
+
},
|
|
304
|
+
indigo: {
|
|
305
|
+
'@light': '$(indigo-60)',
|
|
306
|
+
'@dark': '$(indigo-30)'
|
|
307
|
+
},
|
|
308
|
+
violet: {
|
|
309
|
+
'@light': '$(violet-60)',
|
|
310
|
+
'@dark': '$(violet-30)'
|
|
311
|
+
},
|
|
312
|
+
purple: {
|
|
313
|
+
'@light': '$(purple-60)',
|
|
314
|
+
'@dark': '$(purple-30)'
|
|
315
|
+
},
|
|
316
|
+
fuchsia: {
|
|
317
|
+
'@light': '$(fuchsia-60)',
|
|
318
|
+
'@dark': '$(fuchsia-30)'
|
|
319
|
+
},
|
|
320
|
+
pink: {
|
|
321
|
+
'@light': '$(pink-60)',
|
|
322
|
+
'@dark': '$(pink-30)'
|
|
323
|
+
},
|
|
324
|
+
crimson: {
|
|
325
|
+
'@light': '$(crimson-60)',
|
|
326
|
+
'@dark': '$(crimson-30)'
|
|
327
|
+
},
|
|
328
|
+
red: {
|
|
329
|
+
'@light': '$(red-60)',
|
|
330
|
+
'@dark': '$(red-30)'
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
});
|
|
124
334
|
|
|
125
335
|
export { variables as default };
|
package/dist/core.cjs
CHANGED
|
@@ -12,14 +12,14 @@ var extendConfig = require('./utils/extend-config.cjs');
|
|
|
12
12
|
class MasterCSS {
|
|
13
13
|
customConfig;
|
|
14
14
|
static config = index.config;
|
|
15
|
-
|
|
15
|
+
syntaxes;
|
|
16
16
|
ruleBy;
|
|
17
17
|
classesUsage;
|
|
18
18
|
config;
|
|
19
19
|
Rules;
|
|
20
20
|
constructor(customConfig){
|
|
21
21
|
this.customConfig = customConfig;
|
|
22
|
-
this.
|
|
22
|
+
this.syntaxes = [];
|
|
23
23
|
this.ruleBy = {};
|
|
24
24
|
this.classesUsage = {};
|
|
25
25
|
this.Rules = [];
|
|
@@ -48,7 +48,7 @@ class MasterCSS {
|
|
|
48
48
|
currentColor: undefined,
|
|
49
49
|
transparent: undefined
|
|
50
50
|
};
|
|
51
|
-
const { styles, selectors, variables, utilities, at,
|
|
51
|
+
const { styles, selectors, variables, utilities, at, syntaxes, animations } = this.config;
|
|
52
52
|
function escapeString(str) {
|
|
53
53
|
return str.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
54
54
|
}
|
|
@@ -317,7 +317,7 @@ class MasterCSS {
|
|
|
317
317
|
for (const eachUtilityName of utilityNames){
|
|
318
318
|
handleUtilityName(eachUtilityName);
|
|
319
319
|
}
|
|
320
|
-
if (
|
|
320
|
+
if (syntaxes || utilities) {
|
|
321
321
|
const rulesEntries = [];
|
|
322
322
|
if (utilities) {
|
|
323
323
|
for(const utilityName in utilities){
|
|
@@ -331,8 +331,8 @@ class MasterCSS {
|
|
|
331
331
|
]);
|
|
332
332
|
}
|
|
333
333
|
}
|
|
334
|
-
if (
|
|
335
|
-
rulesEntries.push(...Object.entries(
|
|
334
|
+
if (syntaxes) {
|
|
335
|
+
rulesEntries.push(...Object.entries(syntaxes));
|
|
336
336
|
}
|
|
337
337
|
const rulesEntriesLength = rulesEntries.length;
|
|
338
338
|
const colorNames = Object.keys(colorVariableNames);
|
|
@@ -341,17 +341,17 @@ class MasterCSS {
|
|
|
341
341
|
return (b[1].layer || 0) - (a[1].layer || 0);
|
|
342
342
|
}
|
|
343
343
|
return b[0].localeCompare(a[0]);
|
|
344
|
-
}).forEach(([id,
|
|
344
|
+
}).forEach(([id, eachSyntaxDefinition], index)=>{
|
|
345
345
|
const EachRule = {
|
|
346
346
|
id,
|
|
347
347
|
keys: [],
|
|
348
348
|
variables: {},
|
|
349
349
|
matchers: {},
|
|
350
350
|
order: rulesEntriesLength - 1 - index,
|
|
351
|
-
definition:
|
|
351
|
+
definition: eachSyntaxDefinition
|
|
352
352
|
};
|
|
353
353
|
this.Rules.push(EachRule);
|
|
354
|
-
const { matcher, layer: layer$1, subkey, ambiguousKeys, ambiguousValues, sign } =
|
|
354
|
+
const { matcher, layer: layer$1, subkey, ambiguousKeys, ambiguousValues, sign } = eachSyntaxDefinition;
|
|
355
355
|
if (layer$1 === layer.Utility) {
|
|
356
356
|
EachRule.id = '.' + id;
|
|
357
357
|
EachRule.matchers.arbitrary = new RegExp('^' + escapeString(id) + '(?=!|\\*|>|\\+|~|:|\\[|@|_|\\.|$)', 'm');
|
|
@@ -365,18 +365,18 @@ class MasterCSS {
|
|
|
365
365
|
}
|
|
366
366
|
}
|
|
367
367
|
};
|
|
368
|
-
// 1. custom `config.
|
|
369
|
-
if (
|
|
370
|
-
for (const eachVariableGroup of
|
|
368
|
+
// 1. custom `config.syntaxes[id].variables`
|
|
369
|
+
if (eachSyntaxDefinition.variables) {
|
|
370
|
+
for (const eachVariableGroup of eachSyntaxDefinition.variables){
|
|
371
371
|
addResolvedVariables(eachVariableGroup);
|
|
372
372
|
}
|
|
373
373
|
}
|
|
374
374
|
// 2. custom `config.variables`
|
|
375
375
|
addResolvedVariables(id);
|
|
376
376
|
const keys = [];
|
|
377
|
-
let { key } =
|
|
377
|
+
let { key } = eachSyntaxDefinition;
|
|
378
378
|
if (layer$1 === layer.NativeShorthand || layer$1 === layer.Native) {
|
|
379
|
-
if (!key)
|
|
379
|
+
if (!key) eachSyntaxDefinition.key = key = id;
|
|
380
380
|
keys.push(id);
|
|
381
381
|
}
|
|
382
382
|
if (sign) {
|
|
@@ -451,13 +451,13 @@ class MasterCSS {
|
|
|
451
451
|
}
|
|
452
452
|
}
|
|
453
453
|
/**
|
|
454
|
-
* Generate
|
|
454
|
+
* Generate syntaxes from class name
|
|
455
455
|
* @param className
|
|
456
456
|
* @returns Rule[]
|
|
457
457
|
*/ generate(className) {
|
|
458
458
|
return (Object.prototype.hasOwnProperty.call(this.styles, className) ? this.styles[className].map((eachSyntax)=>this.create(eachSyntax)) : [
|
|
459
459
|
this.create(className)
|
|
460
|
-
]).filter((
|
|
460
|
+
]).filter((eachSyntax)=>eachSyntax && eachSyntax?.text);
|
|
461
461
|
}
|
|
462
462
|
/**
|
|
463
463
|
* Create rule from given syntax
|
|
@@ -486,12 +486,12 @@ class MasterCSS {
|
|
|
486
486
|
this.config = extendConfig(customConfig);
|
|
487
487
|
}
|
|
488
488
|
this.resolve();
|
|
489
|
-
this.
|
|
489
|
+
this.syntaxes.length = 0;
|
|
490
490
|
// @ts-ignore
|
|
491
491
|
this.ruleBy = {};
|
|
492
492
|
/**
|
|
493
|
-
* 拿當前所有的 classNames 按照最新的 colors, config.
|
|
494
|
-
* 所以 refresh 過後
|
|
493
|
+
* 拿當前所有的 classNames 按照最新的 colors, config.syntaxes 匹配並生成新的 style
|
|
494
|
+
* 所以 refresh 過後 syntaxes 可能會變多也可能會變少
|
|
495
495
|
*/ for(const name in this.classesUsage){
|
|
496
496
|
this.add(name);
|
|
497
497
|
}
|
|
@@ -502,7 +502,7 @@ class MasterCSS {
|
|
|
502
502
|
this.ruleBy = {};
|
|
503
503
|
// @ts-ignore
|
|
504
504
|
this.classesUsage = {};
|
|
505
|
-
this.
|
|
505
|
+
this.syntaxes.length = 0;
|
|
506
506
|
this.hasKeyframesRule = false;
|
|
507
507
|
this.variablesNativeRules = {};
|
|
508
508
|
for(const keyframeName in this.animations){
|
|
@@ -523,9 +523,9 @@ class MasterCSS {
|
|
|
523
523
|
}
|
|
524
524
|
add(...classNames) {
|
|
525
525
|
for (const className of classNames){
|
|
526
|
-
const
|
|
527
|
-
if (
|
|
528
|
-
for (const rule of
|
|
526
|
+
const syntaxes = this.generate(className);
|
|
527
|
+
if (syntaxes.length) {
|
|
528
|
+
for (const rule of syntaxes){
|
|
529
529
|
this.insert(rule);
|
|
530
530
|
}
|
|
531
531
|
}
|
|
@@ -552,7 +552,7 @@ class MasterCSS {
|
|
|
552
552
|
}
|
|
553
553
|
}
|
|
554
554
|
}
|
|
555
|
-
this.
|
|
555
|
+
this.syntaxes.splice(this.syntaxes.indexOf(rule), 1);
|
|
556
556
|
delete this.ruleBy[name];
|
|
557
557
|
// variables
|
|
558
558
|
if (rule.variableNames) {
|
|
@@ -564,13 +564,13 @@ class MasterCSS {
|
|
|
564
564
|
const nativeRule = this.variablesNativeRules[mode];
|
|
565
565
|
nativeRule.cssRule.style.removeProperty('--' + eachVariableName);
|
|
566
566
|
if (!nativeRule.cssRule.style.length) {
|
|
567
|
-
const variablesRule = this.
|
|
567
|
+
const variablesRule = this.syntaxes[0];
|
|
568
568
|
const index = variablesRule.natives.indexOf(nativeRule);
|
|
569
569
|
sheet?.deleteRule(index);
|
|
570
570
|
variablesRule.natives.splice(index, 1);
|
|
571
571
|
delete this.variablesNativeRules[mode];
|
|
572
572
|
if (!variablesRule.natives.length) {
|
|
573
|
-
this.
|
|
573
|
+
this.syntaxes.splice(0, 1);
|
|
574
574
|
this.variablesNativeRules = {};
|
|
575
575
|
}
|
|
576
576
|
}
|
|
@@ -589,7 +589,7 @@ class MasterCSS {
|
|
|
589
589
|
// animations
|
|
590
590
|
if (rule.animationNames) {
|
|
591
591
|
const keyframeRulesIndex = Object.keys(this.variablesNativeRules).length ? 1 : 0;
|
|
592
|
-
const keyframeRule = this.
|
|
592
|
+
const keyframeRule = this.syntaxes[keyframeRulesIndex];
|
|
593
593
|
for (const eachKeyframeName of rule.animationNames){
|
|
594
594
|
const keyframe = this.animations[eachKeyframeName];
|
|
595
595
|
if (!keyframe.usage) keyframe.usage = 0;
|
|
@@ -601,7 +601,7 @@ class MasterCSS {
|
|
|
601
601
|
}
|
|
602
602
|
}
|
|
603
603
|
if (!keyframeRule.natives.length) {
|
|
604
|
-
this.
|
|
604
|
+
this.syntaxes.splice(keyframeRulesIndex, 1);
|
|
605
605
|
this.hasKeyframesRule = false;
|
|
606
606
|
}
|
|
607
607
|
}
|
|
@@ -642,28 +642,28 @@ class MasterCSS {
|
|
|
642
642
|
* 以實現響應式先後套用的規則
|
|
643
643
|
* @example <1 <2 <3 ALL >=1 >=2 >=3
|
|
644
644
|
* @description
|
|
645
|
-
*/ const endIndex = this.
|
|
645
|
+
*/ const endIndex = this.syntaxes.length - 1;
|
|
646
646
|
const { at, atToken, order, priority, hasWhere, className } = rule;
|
|
647
647
|
const findIndex = (startIndex, stopCheck, matchCheck)=>{
|
|
648
648
|
let i = startIndex;
|
|
649
649
|
for(; i <= endIndex; i++){
|
|
650
|
-
const
|
|
651
|
-
if (stopCheck?.(
|
|
652
|
-
if (matchCheck?.(
|
|
650
|
+
const eachSyntax = this.syntaxes[i];
|
|
651
|
+
if (stopCheck?.(eachSyntax)) return matchCheck ? -1 : i - 1;
|
|
652
|
+
if (matchCheck?.(eachSyntax)) return i;
|
|
653
653
|
}
|
|
654
654
|
return matchCheck ? -1 : i - 1;
|
|
655
655
|
};
|
|
656
656
|
let matchStartIndex;
|
|
657
657
|
let matchEndIndex;
|
|
658
658
|
if (atToken) {
|
|
659
|
-
const mediaStartIndex = this.
|
|
659
|
+
const mediaStartIndex = this.syntaxes.findIndex((eachSyntax)=>eachSyntax.at?.media);
|
|
660
660
|
if (mediaStartIndex === -1) {
|
|
661
661
|
index = endIndex + 1;
|
|
662
662
|
} else {
|
|
663
663
|
const maxWidthFeature = at.media?.find(({ name })=>name === 'max-width');
|
|
664
664
|
const minWidthFeature = at.media?.find(({ name })=>name === 'min-width');
|
|
665
665
|
if (maxWidthFeature || minWidthFeature) {
|
|
666
|
-
const mediaWidthStartIndex = this.
|
|
666
|
+
const mediaWidthStartIndex = this.syntaxes.findIndex((eachSyntax)=>eachSyntax.at?.media?.find(({ name })=>name === 'max-width' || name === 'min-width'));
|
|
667
667
|
if (mediaWidthStartIndex === -1) {
|
|
668
668
|
index = endIndex + 1;
|
|
669
669
|
} else {
|
|
@@ -674,10 +674,10 @@ class MasterCSS {
|
|
|
674
674
|
* find 第一個所遇到同樣 feature 且範圍值比自己大的 rule,
|
|
675
675
|
* 並插入在該 rule 之後,讓自己優先被套用
|
|
676
676
|
*/ if (priority === -1) {
|
|
677
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (
|
|
678
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (
|
|
677
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntax)=>eachSyntax.priority !== -1, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width') && eachSyntax.at.media?.find(({ name })=>name === 'min-width'));
|
|
678
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntax)=>eachSyntax.priority !== -1);
|
|
679
679
|
} else {
|
|
680
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, undefined, (
|
|
680
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, undefined, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width') && eachSyntax.at.media?.find(({ name })=>name === 'min-width') && eachSyntax.priority !== -1);
|
|
681
681
|
matchEndIndex = endIndex;
|
|
682
682
|
}
|
|
683
683
|
if (matchStartIndex !== -1) {
|
|
@@ -686,9 +686,9 @@ class MasterCSS {
|
|
|
686
686
|
const endI = matchStartIndex;
|
|
687
687
|
matchStartIndex = matchEndIndex + 1;
|
|
688
688
|
for(; i >= endI; i--){
|
|
689
|
-
const
|
|
690
|
-
const eachMaxWidthFeature =
|
|
691
|
-
const eachMinWidthFeature =
|
|
689
|
+
const eachSyntax = this.syntaxes[i];
|
|
690
|
+
const eachMaxWidthFeature = eachSyntax.at.media?.find(({ name })=>name === 'max-width');
|
|
691
|
+
const eachMinWidthFeature = eachSyntax.at.media?.find(({ name })=>name === 'min-width');
|
|
692
692
|
if (!eachMaxWidthFeature || !eachMinWidthFeature) {
|
|
693
693
|
break;
|
|
694
694
|
} else {
|
|
@@ -708,15 +708,15 @@ class MasterCSS {
|
|
|
708
708
|
* find 第一個所遇到同樣 feature 且值比自己大的 rule,
|
|
709
709
|
* 並插入在該 rule 之後,讓自己優先被套用
|
|
710
710
|
*/ if (priority === -1) {
|
|
711
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (
|
|
712
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (
|
|
711
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width') && eachSyntax.at.media?.find(({ name })=>name === 'min-width') || eachSyntax.priority !== -1, (eachSyntax)=>!eachSyntax.at.media?.find(({ name })=>name === 'max-width') && eachSyntax.at.media?.find(({ name })=>name === 'min-width'));
|
|
712
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width') && eachSyntax.at.media?.find(({ name })=>name === 'min-width') || eachSyntax.priority !== -1);
|
|
713
713
|
} else {
|
|
714
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (
|
|
715
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (
|
|
714
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width') && eachSyntax.at.media?.find(({ name })=>name === 'min-width') && eachSyntax.priority !== -1, (eachSyntax)=>!eachSyntax.at.media?.find(({ name })=>name === 'max-width') && eachSyntax.at.media?.find(({ name })=>name === 'min-width') && eachSyntax.priority !== -1);
|
|
715
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width') && eachSyntax.at.media?.find(({ name })=>name === 'min-width') && eachSyntax.priority !== -1);
|
|
716
716
|
}
|
|
717
717
|
if (matchStartIndex !== -1) {
|
|
718
718
|
for(let i = matchEndIndex; i >= matchStartIndex; i--){
|
|
719
|
-
const value = (this.
|
|
719
|
+
const value = (this.syntaxes[i].at.media?.find(({ name })=>name === 'min-width')).value;
|
|
720
720
|
if (value > minWidthFeature.value) {
|
|
721
721
|
matchEndIndex = i - 1;
|
|
722
722
|
} else if (value < minWidthFeature.value) {
|
|
@@ -730,15 +730,15 @@ class MasterCSS {
|
|
|
730
730
|
* find 第一個所遇到同樣 feature 且值比自己大的 rule,
|
|
731
731
|
* 並插入在該 rule 之後,讓自己優先被套用
|
|
732
732
|
*/ if (priority === -1) {
|
|
733
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (
|
|
734
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (
|
|
733
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'min-width') || eachSyntax.priority !== -1, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width'));
|
|
734
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'min-width') || eachSyntax.priority !== -1);
|
|
735
735
|
} else {
|
|
736
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (
|
|
737
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (
|
|
736
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'min-width') && eachSyntax.priority !== -1, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width') && eachSyntax.priority !== -1);
|
|
737
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'min-width') && eachSyntax.priority !== -1);
|
|
738
738
|
}
|
|
739
739
|
if (matchStartIndex !== -1) {
|
|
740
740
|
for(let i = matchEndIndex; i >= matchStartIndex; i--){
|
|
741
|
-
const value = (this.
|
|
741
|
+
const value = (this.syntaxes[i].at.media?.find(({ name })=>name === 'max-width')).value;
|
|
742
742
|
if (value < maxWidthFeature.value) {
|
|
743
743
|
matchEndIndex = i - 1;
|
|
744
744
|
} else if (value > maxWidthFeature.value) {
|
|
@@ -752,10 +752,10 @@ class MasterCSS {
|
|
|
752
752
|
} else {
|
|
753
753
|
if (priority === -1) {
|
|
754
754
|
matchStartIndex = mediaStartIndex;
|
|
755
|
-
matchEndIndex = findIndex(mediaStartIndex, (
|
|
755
|
+
matchEndIndex = findIndex(mediaStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width') || eachSyntax.priority !== -1);
|
|
756
756
|
} else {
|
|
757
|
-
matchStartIndex = findIndex(mediaStartIndex, (
|
|
758
|
-
matchEndIndex = findIndex(mediaStartIndex, (
|
|
757
|
+
matchStartIndex = findIndex(mediaStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width'), (eachSyntax)=>eachSyntax.priority !== -1);
|
|
758
|
+
matchEndIndex = findIndex(mediaStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width'));
|
|
759
759
|
}
|
|
760
760
|
}
|
|
761
761
|
}
|
|
@@ -763,10 +763,10 @@ class MasterCSS {
|
|
|
763
763
|
const findStartIndex = Object.keys(this.variablesNativeRules).length ? this.hasKeyframesRule ? 2 : 1 : this.hasKeyframesRule ? 1 : 0;
|
|
764
764
|
if (priority === -1) {
|
|
765
765
|
matchStartIndex = findStartIndex;
|
|
766
|
-
matchEndIndex = findIndex(findStartIndex, (
|
|
766
|
+
matchEndIndex = findIndex(findStartIndex, (eachSyntax)=>eachSyntax.atToken || eachSyntax.priority !== -1);
|
|
767
767
|
} else {
|
|
768
|
-
matchStartIndex = findIndex(findStartIndex, (
|
|
769
|
-
matchEndIndex = findIndex(findStartIndex, (
|
|
768
|
+
matchStartIndex = findIndex(findStartIndex, (eachSyntax)=>eachSyntax.atToken, (eachSyntax)=>eachSyntax.priority !== -1);
|
|
769
|
+
matchEndIndex = findIndex(findStartIndex, (eachSyntax)=>eachSyntax.atToken);
|
|
770
770
|
}
|
|
771
771
|
}
|
|
772
772
|
if (index === undefined && matchEndIndex !== undefined && matchStartIndex !== undefined) {
|
|
@@ -775,7 +775,7 @@ class MasterCSS {
|
|
|
775
775
|
} else {
|
|
776
776
|
if (priority === -1) {
|
|
777
777
|
for(let i = matchStartIndex; i <= matchEndIndex; i++){
|
|
778
|
-
const currentRule = this.
|
|
778
|
+
const currentRule = this.syntaxes[i];
|
|
779
779
|
if (!hasWhere && currentRule.hasWhere) continue;
|
|
780
780
|
if (hasWhere && !currentRule.hasWhere || currentRule.order >= order) {
|
|
781
781
|
index = i;
|
|
@@ -784,7 +784,7 @@ class MasterCSS {
|
|
|
784
784
|
}
|
|
785
785
|
} else {
|
|
786
786
|
for(let i = matchStartIndex; i <= matchEndIndex; i++){
|
|
787
|
-
const currentRule = this.
|
|
787
|
+
const currentRule = this.syntaxes[i];
|
|
788
788
|
if (!hasWhere && currentRule.hasWhere) continue;
|
|
789
789
|
if (hasWhere && !currentRule.hasWhere) {
|
|
790
790
|
index = i;
|
|
@@ -808,13 +808,13 @@ class MasterCSS {
|
|
|
808
808
|
}
|
|
809
809
|
}
|
|
810
810
|
}
|
|
811
|
-
this.
|
|
811
|
+
this.syntaxes.splice(index, 0, rule);
|
|
812
812
|
this.ruleBy[className] = rule;
|
|
813
813
|
if (this.style) {
|
|
814
814
|
const sheet = this.style.sheet;
|
|
815
815
|
let cssRuleIndex = 0;
|
|
816
816
|
const getCssRuleIndex = (index)=>{
|
|
817
|
-
const previousRule = this.
|
|
817
|
+
const previousRule = this.syntaxes[index];
|
|
818
818
|
if (previousRule) {
|
|
819
819
|
if (!previousRule.natives.length) return getCssRuleIndex(index - 1);
|
|
820
820
|
const lastNative = previousRule.natives[previousRule.natives.length - 1];
|
|
@@ -848,7 +848,7 @@ class MasterCSS {
|
|
|
848
848
|
return index;
|
|
849
849
|
}
|
|
850
850
|
get text() {
|
|
851
|
-
return this.
|
|
851
|
+
return this.syntaxes.map((eachSyntax)=>eachSyntax.text).join('');
|
|
852
852
|
}
|
|
853
853
|
handleRuleWithAnimationNames(rule, initializing = false) {
|
|
854
854
|
if (rule.animationNames) {
|
|
@@ -864,9 +864,9 @@ class MasterCSS {
|
|
|
864
864
|
const keyframeRulesIndex = Object.keys(this.variablesNativeRules).length ? 1 : 0;
|
|
865
865
|
let keyframeRule;
|
|
866
866
|
if (this.hasKeyframesRule) {
|
|
867
|
-
(keyframeRule = this.
|
|
867
|
+
(keyframeRule = this.syntaxes[keyframeRulesIndex]).natives.push(nativeRule);
|
|
868
868
|
} else {
|
|
869
|
-
this.
|
|
869
|
+
this.syntaxes.splice(keyframeRulesIndex, 0, keyframeRule = {
|
|
870
870
|
natives: [
|
|
871
871
|
nativeRule
|
|
872
872
|
],
|
|
@@ -934,7 +934,7 @@ class MasterCSS {
|
|
|
934
934
|
selectorText = ':root';
|
|
935
935
|
}
|
|
936
936
|
if (sheet) {
|
|
937
|
-
const newCSSRuleIndex = Object.keys(this.variablesNativeRules).length ? this.
|
|
937
|
+
const newCSSRuleIndex = Object.keys(this.variablesNativeRules).length ? this.syntaxes[0].natives.length : 0;
|
|
938
938
|
sheet.insertRule((mediaConditionText ? mediaConditionText + '{' : '') + selectorText + '{}' + (mediaConditionText ? mediaConditionText + '}' : ''), newCSSRuleIndex);
|
|
939
939
|
cssRule = mediaConditionText ? sheet.cssRules[newCSSRuleIndex].cssRules[0] : sheet.cssRules[newCSSRuleIndex];
|
|
940
940
|
} else {
|
|
@@ -1006,7 +1006,7 @@ class MasterCSS {
|
|
|
1006
1006
|
return this.natives.map((eachNative)=>eachNative.text).join('');
|
|
1007
1007
|
}
|
|
1008
1008
|
};
|
|
1009
|
-
this.
|
|
1009
|
+
this.syntaxes.splice(0, 0, newRule);
|
|
1010
1010
|
}
|
|
1011
1011
|
let prefix = '';
|
|
1012
1012
|
let suffix = '}';
|
|
@@ -1026,7 +1026,7 @@ class MasterCSS {
|
|
|
1026
1026
|
return prefix + properties.join(';') + suffix;
|
|
1027
1027
|
}
|
|
1028
1028
|
};
|
|
1029
|
-
this.
|
|
1029
|
+
this.syntaxes[0].natives.push(this.variablesNativeRules[mode] = nativeRule);
|
|
1030
1030
|
return nativeRule;
|
|
1031
1031
|
}
|
|
1032
1032
|
}
|
package/dist/core.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export type Variable = TypeVariable & VariableCommon;
|
|
|
28
28
|
export default class MasterCSS {
|
|
29
29
|
customConfig?: Config | undefined;
|
|
30
30
|
static config: Config;
|
|
31
|
-
readonly
|
|
31
|
+
readonly syntaxes: Rule[];
|
|
32
32
|
readonly ruleBy: Record<string, Rule>;
|
|
33
33
|
readonly classesUsage: Record<string, number>;
|
|
34
34
|
readonly config: Config;
|
|
@@ -42,7 +42,7 @@ export default class MasterCSS {
|
|
|
42
42
|
*/
|
|
43
43
|
match(className: string): RegisteredRule | undefined;
|
|
44
44
|
/**
|
|
45
|
-
* Generate
|
|
45
|
+
* Generate syntaxes from class name
|
|
46
46
|
* @param className
|
|
47
47
|
* @returns Rule[]
|
|
48
48
|
*/
|