@master/css 2.0.0-rc.61 → 2.0.0-rc.63
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/animation-rule.cjs +24 -0
- package/dist/animation-rule.d.ts +11 -0
- package/dist/animation-rule.mjs +22 -0
- package/dist/common.cjs +52 -1
- package/dist/common.d.ts +15 -0
- package/dist/common.mjs +46 -2
- package/dist/config/at.cjs +13 -10
- package/dist/config/at.d.ts +4 -1
- package/dist/config/at.mjs +13 -10
- package/dist/config/index.cjs +3 -0
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.mjs +3 -1
- package/dist/config/modes.d.ts +4 -2
- package/dist/config/rules.cjs +25 -13
- package/dist/config/rules.d.ts +4 -2
- package/dist/config/rules.mjs +25 -13
- package/dist/config/screens.cjs +17 -0
- package/dist/config/screens.d.ts +14 -0
- package/dist/config/screens.mjs +15 -0
- package/dist/config/selectors.cjs +11 -15
- package/dist/config/selectors.d.ts +10 -8
- package/dist/config/selectors.mjs +11 -15
- package/dist/config/utilities.cjs +3 -0
- package/dist/config/utilities.d.ts +3 -0
- package/dist/config/utilities.mjs +3 -0
- package/dist/config/variables.cjs +0 -13
- package/dist/config/variables.d.ts +0 -13
- package/dist/config/variables.mjs +0 -13
- package/dist/core.cjs +438 -476
- package/dist/core.d.ts +13 -4
- package/dist/core.mjs +438 -476
- package/dist/factories/with-syntax-layer.cjs +37 -260
- package/dist/factories/with-syntax-layer.mjs +37 -260
- package/dist/index.cjs +39 -12
- package/dist/index.d.ts +19 -7
- package/dist/index.mjs +17 -7
- package/dist/layer.cjs +11 -7
- package/dist/layer.d.ts +4 -3
- package/dist/layer.mjs +11 -7
- package/dist/non-layer.cjs +10 -17
- package/dist/non-layer.d.ts +1 -1
- package/dist/non-layer.mjs +10 -17
- package/dist/rule.cjs +4 -6
- package/dist/rule.d.ts +3 -10
- package/dist/rule.mjs +4 -6
- package/dist/syntax-rule-type.cjs +7 -8
- package/dist/syntax-rule-type.d.ts +7 -7
- package/dist/syntax-rule-type.mjs +7 -8
- package/dist/syntax-rule.cjs +116 -328
- package/dist/syntax-rule.d.ts +18 -25
- package/dist/syntax-rule.mjs +117 -329
- package/dist/types/common.d.ts +2 -0
- package/dist/types/config.d.ts +12 -7
- package/dist/types/syntax.d.ts +5 -24
- package/dist/utils/compare-rule-priority.cjs +143 -0
- package/dist/utils/compare-rule-priority.d.ts +7 -0
- package/dist/utils/compare-rule-priority.mjs +138 -0
- package/dist/utils/equal-at-rules.cjs +22 -0
- package/dist/utils/equal-at-rules.d.ts +2 -0
- package/dist/utils/equal-at-rules.mjs +20 -0
- package/dist/utils/equal-declarations.cjs +10 -0
- package/dist/utils/equal-declarations.d.ts +2 -0
- package/dist/utils/equal-declarations.mjs +8 -0
- package/dist/utils/equal-selectors.cjs +70 -0
- package/dist/utils/equal-selectors.d.ts +2 -0
- package/dist/utils/equal-selectors.mjs +68 -0
- package/dist/utils/equal-variants.cjs +10 -0
- package/dist/utils/equal-variants.d.ts +2 -0
- package/dist/utils/equal-variants.mjs +8 -0
- package/dist/utils/extend-config.cjs +0 -1
- package/dist/utils/extend-config.mjs +0 -1
- package/dist/utils/generate-at.cjs +30 -0
- package/dist/utils/generate-at.d.ts +2 -0
- package/dist/utils/generate-at.mjs +28 -0
- package/dist/utils/generate-selector.cjs +49 -0
- package/dist/utils/generate-selector.d.ts +2 -0
- package/dist/utils/generate-selector.mjs +47 -0
- package/dist/utils/get-single-at-number-rule-node.cjs +9 -0
- package/dist/utils/get-single-at-number-rule-node.d.ts +2 -0
- package/dist/utils/get-single-at-number-rule-node.mjs +7 -0
- package/dist/utils/parse-at.cjs +157 -0
- package/dist/utils/parse-at.d.ts +39 -0
- package/dist/utils/parse-at.mjs +155 -0
- package/dist/utils/parse-pair.cjs +51 -0
- package/dist/utils/parse-pair.d.ts +8 -0
- package/dist/utils/parse-pair.mjs +49 -0
- package/dist/utils/parse-selector.cjs +114 -0
- package/dist/utils/parse-selector.d.ts +19 -0
- package/dist/utils/parse-selector.mjs +112 -0
- package/dist/utils/parse-value.cjs +39 -0
- package/dist/utils/parse-value.d.ts +2 -0
- package/dist/utils/parse-value.mjs +37 -0
- package/dist/utils/replace-char-outside-quotes.cjs +21 -0
- package/dist/utils/replace-char-outside-quotes.d.ts +1 -0
- package/dist/utils/replace-char-outside-quotes.mjs +19 -0
- package/dist/utils/sort-readable-classes.cjs +86 -0
- package/dist/utils/{reorder-for-readable-classes.d.ts → sort-readable-classes.d.ts} +1 -1
- package/dist/utils/sort-readable-classes.mjs +84 -0
- package/dist/utils/split-char-outside-quotes.cjs +29 -0
- package/dist/utils/split-char-outside-quotes.d.ts +1 -0
- package/dist/utils/split-char-outside-quotes.mjs +27 -0
- package/dist/variable-rule.cjs +86 -0
- package/dist/variable-rule.d.ts +23 -0
- package/dist/variable-rule.mjs +81 -0
- package/package.json +1 -1
- package/dist/rule-node.cjs +0 -18
- package/dist/rule-node.d.ts +0 -14
- package/dist/rule-node.mjs +0 -16
- package/dist/utils/are-rule-at-equal.cjs +0 -12
- package/dist/utils/are-rule-at-equal.d.ts +0 -2
- package/dist/utils/are-rule-at-equal.mjs +0 -10
- package/dist/utils/are-rule-modes-equal.cjs +0 -7
- package/dist/utils/are-rule-modes-equal.d.ts +0 -2
- package/dist/utils/are-rule-modes-equal.mjs +0 -5
- package/dist/utils/are-rule-selectors-equal.cjs +0 -29
- package/dist/utils/are-rule-selectors-equal.d.ts +0 -2
- package/dist/utils/are-rule-selectors-equal.mjs +0 -27
- package/dist/utils/are-rule-states-equal.cjs +0 -11
- package/dist/utils/are-rule-states-equal.d.ts +0 -2
- package/dist/utils/are-rule-states-equal.mjs +0 -9
- package/dist/utils/are-rules-duplicated.cjs +0 -17
- package/dist/utils/are-rules-duplicated.d.ts +0 -2
- package/dist/utils/are-rules-duplicated.mjs +0 -15
- package/dist/utils/reorder-for-readable-classes.cjs +0 -62
- package/dist/utils/reorder-for-readable-classes.mjs +0 -60
package/dist/syntax-rule.cjs
CHANGED
|
@@ -3,27 +3,35 @@
|
|
|
3
3
|
var cssEscape = require('./shared/utils/css-escape.cjs');
|
|
4
4
|
var syntaxRuleType = require('./syntax-rule-type.cjs');
|
|
5
5
|
var common = require('./common.cjs');
|
|
6
|
-
var
|
|
6
|
+
var parseValue = require('./utils/parse-value.cjs');
|
|
7
|
+
var parseAt = require('./utils/parse-at.cjs');
|
|
8
|
+
var generateAt = require('./utils/generate-at.cjs');
|
|
9
|
+
var parseSelector = require('./utils/parse-selector.cjs');
|
|
10
|
+
var generateSelector = require('./utils/generate-selector.cjs');
|
|
11
|
+
var compareRulePriority = require('./utils/compare-rule-priority.cjs');
|
|
7
12
|
|
|
8
|
-
class SyntaxRule
|
|
13
|
+
class SyntaxRule {
|
|
9
14
|
name;
|
|
10
15
|
css;
|
|
11
16
|
registeredSyntax;
|
|
12
17
|
fixedClass;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
mediaAtComponents;
|
|
16
|
-
containerAtComponents;
|
|
18
|
+
native;
|
|
19
|
+
atRules;
|
|
17
20
|
priority;
|
|
18
|
-
order;
|
|
19
21
|
type;
|
|
20
22
|
declarations;
|
|
21
23
|
layer;
|
|
22
|
-
|
|
24
|
+
valid;
|
|
23
25
|
animationNames;
|
|
24
26
|
variableNames;
|
|
25
27
|
constructor(name, css, registeredSyntax, fixedClass, mode){
|
|
26
|
-
|
|
28
|
+
this.name = name;
|
|
29
|
+
this.css = css;
|
|
30
|
+
this.registeredSyntax = registeredSyntax;
|
|
31
|
+
this.fixedClass = fixedClass;
|
|
32
|
+
this.type = syntaxRuleType.Normal;
|
|
33
|
+
this.valid = true;
|
|
34
|
+
this.resolveValue = (valueComponents, unit, bypassVariableNames, bypassParsing)=>{
|
|
27
35
|
const { functions } = this.css.config;
|
|
28
36
|
let currentValue = '';
|
|
29
37
|
for (const eachValueComponent of valueComponents){
|
|
@@ -49,11 +57,12 @@ class SyntaxRule extends rule.Rule {
|
|
|
49
57
|
normalHandler(themeVariable);
|
|
50
58
|
}
|
|
51
59
|
} else {
|
|
52
|
-
if (
|
|
53
|
-
this.variableNames
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
if (this.variableNames) {
|
|
61
|
+
this.variableNames.add(eachValueComponent.name);
|
|
62
|
+
} else {
|
|
63
|
+
this.variableNames = new Set([
|
|
64
|
+
eachValueComponent.name
|
|
65
|
+
]);
|
|
57
66
|
}
|
|
58
67
|
varHandler();
|
|
59
68
|
}
|
|
@@ -114,7 +123,8 @@ class SyntaxRule extends rule.Rule {
|
|
|
114
123
|
}
|
|
115
124
|
}
|
|
116
125
|
return currentValue;
|
|
117
|
-
}
|
|
126
|
+
};
|
|
127
|
+
this.parseValues = (currentValueComponents, i, value, unit, endSymbol, parentFunctionName, bypassParsing = false, bypassVariableNames = [])=>{
|
|
118
128
|
const root = parentFunctionName === undefined;
|
|
119
129
|
const isVarFunction = !root && (parentFunctionName.endsWith('$') || parentFunctionName.endsWith('var'));
|
|
120
130
|
const checkIsString = (value)=>value === '\'' || value === '"';
|
|
@@ -168,8 +178,9 @@ class SyntaxRule extends rule.Rule {
|
|
|
168
178
|
token: currentValue
|
|
169
179
|
});
|
|
170
180
|
} else {
|
|
181
|
+
const parsedValue = this.parseValue(currentValue, unit);
|
|
171
182
|
currentValueComponents.push({
|
|
172
|
-
...
|
|
183
|
+
...parsedValue,
|
|
173
184
|
token: currentValue
|
|
174
185
|
});
|
|
175
186
|
}
|
|
@@ -259,20 +270,17 @@ class SyntaxRule extends rule.Rule {
|
|
|
259
270
|
const { id, definition } = registeredSyntax;
|
|
260
271
|
const { analyze, transformValue, declare, transformValueComponents, create, type, unit } = definition;
|
|
261
272
|
this.type = type;
|
|
262
|
-
const { scope, important, modes } = css.config;
|
|
263
|
-
const { at, animations } = css;
|
|
264
273
|
if (create) create.call(this, name);
|
|
265
274
|
// 1. value / selectorToken
|
|
266
275
|
this.declarations = definition.declarations;
|
|
267
276
|
let stateToken;
|
|
268
|
-
let prefixToken;
|
|
269
277
|
if (this.type === syntaxRuleType.Utility) {
|
|
270
278
|
// TODO: id 使用其他方式傳遞
|
|
271
279
|
stateToken = name.slice(id.length - 1);
|
|
272
280
|
} else {
|
|
273
281
|
let valueToken;
|
|
274
282
|
if (analyze) {
|
|
275
|
-
[valueToken
|
|
283
|
+
[valueToken] = analyze.call(this, name);
|
|
276
284
|
} else {
|
|
277
285
|
const indexOfColon = name.indexOf(':');
|
|
278
286
|
this.keyToken = name.slice(0, indexOfColon + 1);
|
|
@@ -289,222 +297,57 @@ class SyntaxRule extends rule.Rule {
|
|
|
289
297
|
stateToken = stateToken.slice(1);
|
|
290
298
|
}
|
|
291
299
|
this.stateToken = stateToken;
|
|
292
|
-
// 3. prefix selector
|
|
293
|
-
if (prefixToken) {
|
|
294
|
-
this.vendorPrefixSelectors = css.generateVendorSelectors(prefixToken);
|
|
295
|
-
}
|
|
296
300
|
// 4. suffix selector
|
|
297
301
|
const stateTokens = stateToken.split('@');
|
|
298
302
|
const suffixSelector = stateTokens[0];
|
|
299
303
|
if (suffixSelector) {
|
|
300
|
-
this.
|
|
301
|
-
for (const suffixSelectors of Object.values(this.vendorSuffixSelectors)){
|
|
302
|
-
for (const eachSuffixSelector of suffixSelectors){
|
|
303
|
-
const SORTED_SELECTORS = [
|
|
304
|
-
':disabled',
|
|
305
|
-
':active',
|
|
306
|
-
':focus',
|
|
307
|
-
':hover'
|
|
308
|
-
];
|
|
309
|
-
for(let i = 0; i < SORTED_SELECTORS.length; i++){
|
|
310
|
-
if (eachSuffixSelector.includes(SORTED_SELECTORS[i])) {
|
|
311
|
-
if (this.priority === -1 || this.priority > i) {
|
|
312
|
-
this.priority = i;
|
|
313
|
-
}
|
|
314
|
-
break;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
// selector combinations
|
|
321
|
-
const suffixSelectorVendorsByPrefixSelectorVendor = {};
|
|
322
|
-
if (this.vendorPrefixSelectors) {
|
|
323
|
-
if (this.vendorSuffixSelectors) {
|
|
324
|
-
for(const prefixSelectorVendor in this.vendorPrefixSelectors){
|
|
325
|
-
const suffixSelectorVendors = suffixSelectorVendorsByPrefixSelectorVendor[prefixSelectorVendor] = [];
|
|
326
|
-
if (Object.prototype.hasOwnProperty.call(this.vendorSuffixSelectors, prefixSelectorVendor)) {
|
|
327
|
-
suffixSelectorVendors.push(prefixSelectorVendor);
|
|
328
|
-
} else {
|
|
329
|
-
for(const suffixVendor in this.vendorSuffixSelectors){
|
|
330
|
-
suffixSelectorVendors.push(suffixVendor);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
} else {
|
|
335
|
-
for(const vendor in this.vendorPrefixSelectors){
|
|
336
|
-
suffixSelectorVendorsByPrefixSelectorVendor[vendor] = [
|
|
337
|
-
''
|
|
338
|
-
];
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
} else {
|
|
342
|
-
suffixSelectorVendorsByPrefixSelectorVendor[''] = this.vendorSuffixSelectors ? Object.keys(this.vendorSuffixSelectors) : [
|
|
343
|
-
''
|
|
344
|
-
];
|
|
304
|
+
this.selectorNodes = parseSelector(suffixSelector, css);
|
|
345
305
|
}
|
|
346
306
|
// 5. atTokens
|
|
347
307
|
for(let i = 1; i < stateTokens.length; i++){
|
|
348
308
|
const atToken = stateTokens[i];
|
|
309
|
+
if (css.config.modes?.[atToken]) {
|
|
310
|
+
this.mode = atToken;
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
349
313
|
this.atToken = (this.atToken || '') + '@' + atToken;
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
this.layerAtComponents = [
|
|
360
|
-
atComponent
|
|
361
|
-
];
|
|
362
|
-
}
|
|
363
|
-
continue;
|
|
364
|
-
} else if (atToken === 'rtl' || atToken === 'ltr') {
|
|
365
|
-
this.direction = atToken;
|
|
366
|
-
} else {
|
|
367
|
-
let queryType;
|
|
368
|
-
const atComponents = [];
|
|
369
|
-
// x font-face, counter-style, keyframes, font-feature-values, property, layer
|
|
370
|
-
const queryTypeRegExp = /^(media|supports|container|layer)/;
|
|
371
|
-
const atRuleResult = queryTypeRegExp.exec(atToken);
|
|
372
|
-
if (atRuleResult) {
|
|
373
|
-
queryType = atRuleResult[1];
|
|
374
|
-
atComponents.push({
|
|
375
|
-
type: 'arbitrary',
|
|
376
|
-
token: atToken,
|
|
377
|
-
value: atToken.slice(queryType.length).replace(/\|/g, ' ')
|
|
378
|
-
});
|
|
379
|
-
} else {
|
|
380
|
-
const analyzeToken = (atComponentToken)=>{
|
|
381
|
-
if (atComponentToken === '&') {
|
|
382
|
-
atComponents.push({
|
|
383
|
-
type: 'operator',
|
|
384
|
-
token: atComponentToken,
|
|
385
|
-
value: 'and'
|
|
386
|
-
});
|
|
387
|
-
} else if (atComponentToken.startsWith('')) {
|
|
388
|
-
const targetAt = at.get(atComponentToken);
|
|
389
|
-
if (typeof targetAt === 'string') {
|
|
390
|
-
const match = targetAt.match(queryTypeRegExp);
|
|
391
|
-
queryType = match ? match[1] : '';
|
|
392
|
-
if (!queryType) throw new Error(`Invalid query '${atComponentToken}': '${targetAt}'`);
|
|
393
|
-
atComponents.push({
|
|
394
|
-
type: 'arbitrary',
|
|
395
|
-
value: targetAt.slice(match ? match[1].length + 1 : 0)
|
|
396
|
-
});
|
|
397
|
-
} else {
|
|
398
|
-
// todo: container queries
|
|
399
|
-
queryType = 'media';
|
|
400
|
-
let featureName = '';
|
|
401
|
-
let extremumOperator = '';
|
|
402
|
-
let correction = 0;
|
|
403
|
-
if (atComponentToken.startsWith('<=')) {
|
|
404
|
-
extremumOperator = '<=';
|
|
405
|
-
featureName = 'max-width';
|
|
406
|
-
} else if (atComponentToken.startsWith('>') && !atComponentToken.startsWith('>=')) {
|
|
407
|
-
extremumOperator = '>';
|
|
408
|
-
featureName = 'min-width';
|
|
409
|
-
correction = .02;
|
|
410
|
-
} else if (atComponentToken.startsWith('<')) {
|
|
411
|
-
extremumOperator = '<';
|
|
412
|
-
featureName = 'max-width';
|
|
413
|
-
correction = -0.02;
|
|
414
|
-
} else if (atComponentToken.startsWith('>=') || targetAt) {
|
|
415
|
-
extremumOperator = '>=';
|
|
416
|
-
featureName = 'min-width';
|
|
417
|
-
}
|
|
418
|
-
const token = extremumOperator ? atComponentToken.replace(extremumOperator, '') : atComponentToken;
|
|
419
|
-
const viewport = at.get(token);
|
|
420
|
-
switch(featureName){
|
|
421
|
-
case 'max-width':
|
|
422
|
-
case 'min-width':
|
|
423
|
-
if (typeof viewport === 'number') {
|
|
424
|
-
atComponents.push({
|
|
425
|
-
type: 'feature',
|
|
426
|
-
name: featureName,
|
|
427
|
-
valueType: 'number',
|
|
428
|
-
value: viewport + correction,
|
|
429
|
-
unit: 'px'
|
|
430
|
-
});
|
|
431
|
-
} else {
|
|
432
|
-
const valueComponent = this.parseValue(token, 'px');
|
|
433
|
-
if (valueComponent.type === 'number') {
|
|
434
|
-
atComponents.push({
|
|
435
|
-
type: 'feature',
|
|
436
|
-
name: featureName,
|
|
437
|
-
valueType: 'number',
|
|
438
|
-
value: valueComponent.value + correction,
|
|
439
|
-
unit: valueComponent.unit
|
|
440
|
-
});
|
|
441
|
-
} else {
|
|
442
|
-
atComponents.push({
|
|
443
|
-
type: 'feature',
|
|
444
|
-
name: featureName,
|
|
445
|
-
valueType: 'string',
|
|
446
|
-
value: token
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
break;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
|
-
const isAmpersandIncluded = atToken.includes('&');
|
|
456
|
-
if (isAmpersandIncluded) {
|
|
457
|
-
const typeOrFeatureTokens = atToken.split(/(&|,)/);
|
|
458
|
-
for (const atComponentToken of typeOrFeatureTokens){
|
|
459
|
-
analyzeToken(atComponentToken);
|
|
460
|
-
}
|
|
461
|
-
} else {
|
|
462
|
-
analyzeToken(atToken);
|
|
463
|
-
}
|
|
464
|
-
if (!atComponents.length) {
|
|
465
|
-
if (!isAmpersandIncluded && modes?.[atToken]) {
|
|
466
|
-
this.mode = atToken;
|
|
467
|
-
continue;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
if (queryType) {
|
|
472
|
-
const targetAtComponents = this[`${queryType}AtComponents`];
|
|
473
|
-
if (targetAtComponents) {
|
|
474
|
-
targetAtComponents.push(...atComponents);
|
|
475
|
-
} else {
|
|
476
|
-
this[`${queryType}AtComponents`] = atComponents;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
}
|
|
314
|
+
const atRule = parseAt(atToken, css);
|
|
315
|
+
const targetNodes = this.atRules?.[atRule.id];
|
|
316
|
+
if (targetNodes) {
|
|
317
|
+
targetNodes.push(...atRule.nodes);
|
|
318
|
+
} else {
|
|
319
|
+
this.atRules = {
|
|
320
|
+
...this.atRules,
|
|
321
|
+
[atRule.id]: atRule.nodes
|
|
322
|
+
};
|
|
480
323
|
}
|
|
481
324
|
}
|
|
482
|
-
if (this.mode && modes?.[this.mode] === 'media') {
|
|
483
|
-
const
|
|
484
|
-
type: 'feature',
|
|
325
|
+
if (this.mode && css.config.modes?.[this.mode] === 'media') {
|
|
326
|
+
const atComp = {
|
|
485
327
|
name: 'prefers-color-scheme',
|
|
486
|
-
valueType: 'string',
|
|
487
328
|
value: this.mode
|
|
488
329
|
};
|
|
489
|
-
if (this.
|
|
490
|
-
this.
|
|
330
|
+
if (this.atRules?.media) {
|
|
331
|
+
this.atRules.media.push(atComp);
|
|
491
332
|
} else {
|
|
492
|
-
this.
|
|
493
|
-
|
|
494
|
-
|
|
333
|
+
this.atRules = {
|
|
334
|
+
media: [
|
|
335
|
+
atComp
|
|
336
|
+
]
|
|
337
|
+
};
|
|
495
338
|
}
|
|
496
339
|
}
|
|
497
340
|
if (this.fixedClass) {
|
|
498
341
|
this.layer = css.componentsLayer;
|
|
499
342
|
} else {
|
|
500
|
-
const
|
|
501
|
-
if (
|
|
502
|
-
if (
|
|
343
|
+
const onlyNode = this.atRules?.layer?.length === 1 && this.atRules.layer[0];
|
|
344
|
+
if (onlyNode) {
|
|
345
|
+
if (onlyNode.value === 'base') {
|
|
503
346
|
this.layer = css.baseLayer;
|
|
504
|
-
this.
|
|
505
|
-
} else if (
|
|
347
|
+
this.atRules.layer = undefined;
|
|
348
|
+
} else if (onlyNode.value === 'preset') {
|
|
506
349
|
this.layer = css.presetLayer;
|
|
507
|
-
this.
|
|
350
|
+
this.atRules.layer = undefined;
|
|
508
351
|
}
|
|
509
352
|
}
|
|
510
353
|
}
|
|
@@ -526,137 +369,82 @@ class SyntaxRule extends rule.Rule {
|
|
|
526
369
|
};
|
|
527
370
|
}
|
|
528
371
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
const
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
372
|
+
if (!Object.entries(this.declarations ?? {}).length) {
|
|
373
|
+
this.valid = false;
|
|
374
|
+
} else {
|
|
375
|
+
for(const propertyName in this.declarations){
|
|
376
|
+
if (this.css.animations && (propertyName === 'animation' || propertyName === 'animation-name')) {
|
|
377
|
+
const propertyValue = this.declarations[propertyName];
|
|
378
|
+
if (!propertyValue) continue;
|
|
379
|
+
const rawValues = propertyValue.split(' ');
|
|
380
|
+
for (const rawValue of rawValues){
|
|
381
|
+
if (this.css.animations.has(rawValue)) {
|
|
382
|
+
if (!this.animationNames) {
|
|
383
|
+
this.animationNames = new Set([
|
|
384
|
+
rawValue
|
|
385
|
+
]);
|
|
386
|
+
} else {
|
|
387
|
+
this.animationNames.add(rawValue);
|
|
388
|
+
}
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
538
391
|
}
|
|
539
|
-
this.animationNames = animationNames;
|
|
540
392
|
}
|
|
541
393
|
}
|
|
542
|
-
|
|
394
|
+
this.priority = compareRulePriority.calcRulePriority(this);
|
|
543
395
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
prefixText += '[dir=' + this.direction + '] ';
|
|
553
|
-
}
|
|
554
|
-
const prefixTexts = prefixSelectors ? prefixSelectors.map((eachPrefixSelector)=>eachPrefixSelector + prefixText) : [
|
|
555
|
-
prefixText
|
|
556
|
-
];
|
|
557
|
-
const getCssText = (name)=>prefixTexts.map((eachPrefixText)=>{
|
|
558
|
-
let modePrefix = '';
|
|
559
|
-
if (this.mode) {
|
|
560
|
-
const modeSelector = this.css.getModeSelector(this.mode);
|
|
561
|
-
if (modeSelector) {
|
|
562
|
-
modePrefix = modeSelector + ' ';
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
return modePrefix + (scope ? scope + ' ' : '') + eachPrefixText;
|
|
566
|
-
}).reduce((arr, eachPrefixText)=>{
|
|
567
|
-
arr.push(suffixSelectors ? suffixSelectors.reduce((_arr, eachSuffixSelector)=>{
|
|
568
|
-
_arr.push(eachPrefixText + '.' + cssEscape(name) + eachSuffixSelector);
|
|
569
|
-
return _arr;
|
|
570
|
-
}, []).join(',') : eachPrefixText + '.' + cssEscape(name));
|
|
571
|
-
return arr;
|
|
572
|
-
}, []).join(',');
|
|
573
|
-
const selectorText = getCssText(fixedClass ?? name);
|
|
574
|
-
let cssText = selectorText + '{' + propertiesText.join(';') + '}';
|
|
575
|
-
const resolveAtComponents = (atComponents, separator)=>atComponents.map((atComponent, i)=>{
|
|
576
|
-
const value = this.resolveAtComponent(atComponent);
|
|
577
|
-
return (i === 0 ? value.charAt(0) !== '(' ? ' ' : '' : '') + value;
|
|
578
|
-
}).join(separator) + '{' + cssText + '}';
|
|
579
|
-
if (this.containerAtComponents) cssText = '@container' + resolveAtComponents(this.containerAtComponents, ' ');
|
|
580
|
-
if (this.mediaAtComponents) cssText = '@media' + resolveAtComponents(this.mediaAtComponents, ' ');
|
|
581
|
-
if (this.supportsAtComponents) cssText = '@supports' + resolveAtComponents(this.supportsAtComponents, ' ');
|
|
582
|
-
if (this.layerAtComponents) cssText = '@layer' + resolveAtComponents(this.layerAtComponents, '.');
|
|
583
|
-
const node = {
|
|
584
|
-
text: cssText,
|
|
585
|
-
selectorText
|
|
586
|
-
};
|
|
587
|
-
if (prefixSelectors) node.prefixSelectors = prefixSelectors;
|
|
588
|
-
if (suffixSelectors) node.suffixSelectors = suffixSelectors;
|
|
589
|
-
this.nodes.push(node);
|
|
590
|
-
}
|
|
591
|
-
}
|
|
396
|
+
}
|
|
397
|
+
get text() {
|
|
398
|
+
if (!this.valid) return '';
|
|
399
|
+
const propertiesText = [];
|
|
400
|
+
for(const propertyName in this.declarations){
|
|
401
|
+
const propertyValue = this.declarations[propertyName];
|
|
402
|
+
const propertyText = propertyName + ':' + String(propertyValue);
|
|
403
|
+
propertiesText.push(propertyText + ((this.important || this.css.config.important) && !propertyText.endsWith('!important') ? '!important' : ''));
|
|
592
404
|
}
|
|
405
|
+
let text = this.selectorText + '{' + propertiesText.join(';') + '}';
|
|
406
|
+
if (this.atRules !== undefined) common.AT_IDENTIFIERS.forEach((id)=>{
|
|
407
|
+
const nodes = this.atRules?.[id];
|
|
408
|
+
if (!nodes) return;
|
|
409
|
+
text = generateAt({
|
|
410
|
+
id,
|
|
411
|
+
nodes
|
|
412
|
+
}) + '{' + text + '}';
|
|
413
|
+
});
|
|
414
|
+
return text;
|
|
593
415
|
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
416
|
+
get selectorText() {
|
|
417
|
+
let pre = '';
|
|
418
|
+
if (this.css.config.scope) {
|
|
419
|
+
pre = this.css.config.scope + ' ' + pre;
|
|
420
|
+
}
|
|
421
|
+
if (this.mode) {
|
|
422
|
+
const modeSelector = this.css.getModeSelector(this.mode);
|
|
423
|
+
if (modeSelector) {
|
|
424
|
+
pre = modeSelector + ' ' + pre;
|
|
425
|
+
}
|
|
600
426
|
}
|
|
427
|
+
const body = pre + '.' + cssEscape(this.fixedClass ?? this.name);
|
|
428
|
+
return this.selectorNodes ? generateSelector(this.selectorNodes, body) : body;
|
|
601
429
|
}
|
|
602
430
|
resolveValue;
|
|
603
431
|
parseValues;
|
|
604
432
|
parseValue(token, unit = this.definition.unit) {
|
|
605
|
-
const
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
* 將 pxValue / 16 轉為 remValue
|
|
612
|
-
*/ if (defaultUnit && !newUnit) {
|
|
613
|
-
if (defaultUnit === 'rem' || defaultUnit === 'em') {
|
|
614
|
-
value = token / (this.css.config.rootSize || 1);
|
|
615
|
-
}
|
|
616
|
-
newUnit = defaultUnit || '';
|
|
617
|
-
} else {
|
|
618
|
-
value = token;
|
|
619
|
-
}
|
|
620
|
-
return {
|
|
621
|
-
value,
|
|
622
|
-
unit: newUnit,
|
|
623
|
-
type: 'number'
|
|
624
|
-
};
|
|
625
|
-
} else if (defaultUnit) {
|
|
626
|
-
// w:1/2 -> width: 50%
|
|
627
|
-
if (/^\d+\/\d+/.test(token)) {
|
|
628
|
-
const [dividend, divisor] = token.split('/');
|
|
433
|
+
const parsed = parseValue(token, unit, this.css.config.rootSize);
|
|
434
|
+
// exclude like `aspect:1/2` from being parsed as 50%
|
|
435
|
+
if (this.definition.unit && parsed.type === 'string') {
|
|
436
|
+
// 1/2 → 50%
|
|
437
|
+
if (/^\d+\/\d+$/.test(parsed.value)) {
|
|
438
|
+
const [numerator, denominator] = parsed.value.split('/').map(Number);
|
|
629
439
|
return {
|
|
630
|
-
|
|
440
|
+
token,
|
|
441
|
+
value: numerator / denominator * 100,
|
|
631
442
|
unit: '%',
|
|
632
443
|
type: 'number'
|
|
633
444
|
};
|
|
634
445
|
}
|
|
635
|
-
const matches = token.match(common.UNIT_REGEX);
|
|
636
|
-
// ['0.5deg', '0.5', 'deg', index: 0, input: '0.5deg', groups: undefined]
|
|
637
|
-
if (matches) {
|
|
638
|
-
value = +matches[1];
|
|
639
|
-
newUnit = matches[3] || '';
|
|
640
|
-
/**
|
|
641
|
-
* 當無單位值且 defaultUnit === 'rem',
|
|
642
|
-
* 將 pxValue / 16 轉為 remValue
|
|
643
|
-
*/ if (!newUnit) {
|
|
644
|
-
if (defaultUnit === 'rem' || defaultUnit === 'em') {
|
|
645
|
-
value = value / (this.css.config.rootSize || 1);
|
|
646
|
-
}
|
|
647
|
-
newUnit = defaultUnit || '';
|
|
648
|
-
}
|
|
649
|
-
return {
|
|
650
|
-
value,
|
|
651
|
-
unit: newUnit,
|
|
652
|
-
type: 'number'
|
|
653
|
-
};
|
|
654
|
-
}
|
|
655
446
|
}
|
|
656
|
-
return
|
|
657
|
-
value: token,
|
|
658
|
-
type: 'string'
|
|
659
|
-
};
|
|
447
|
+
return parsed;
|
|
660
448
|
}
|
|
661
449
|
get key() {
|
|
662
450
|
return (this.fixedClass ? this.fixedClass + ' ' : '') + this.name;
|
package/dist/syntax-rule.d.ts
CHANGED
|
@@ -1,44 +1,37 @@
|
|
|
1
1
|
import MasterCSS from './core';
|
|
2
|
-
import SyntaxRuleType from './syntax-rule-type';
|
|
3
2
|
import { type PropertiesHyphen } from 'csstype';
|
|
4
|
-
import { Rule } from './rule';
|
|
5
3
|
import Layer from './layer';
|
|
6
|
-
import type {
|
|
7
|
-
|
|
4
|
+
import type { NumberValueComponent, DefinedRule, ValueComponent } from './types/syntax';
|
|
5
|
+
import { AtRuleNode } from './utils/parse-at';
|
|
6
|
+
import { AtIdentifier } from './types/config';
|
|
7
|
+
import { SelectorNode } from './utils/parse-selector';
|
|
8
|
+
import { RulePriority } from './utils/compare-rule-priority';
|
|
9
|
+
import { SyntaxRuleTypeValue } from './types/common';
|
|
10
|
+
export declare class SyntaxRule {
|
|
8
11
|
readonly name: string;
|
|
9
12
|
css: MasterCSS;
|
|
10
13
|
readonly registeredSyntax: DefinedRule;
|
|
11
14
|
fixedClass?: string | undefined;
|
|
12
|
-
|
|
13
|
-
readonly
|
|
14
|
-
readonly
|
|
15
|
-
readonly
|
|
16
|
-
readonly priority: number;
|
|
17
|
-
readonly order: number;
|
|
18
|
-
readonly type: SyntaxRuleType;
|
|
15
|
+
native?: CSSRule;
|
|
16
|
+
readonly atRules?: Partial<Record<AtIdentifier, AtRuleNode[]>>;
|
|
17
|
+
readonly priority: RulePriority;
|
|
18
|
+
readonly type: SyntaxRuleTypeValue;
|
|
19
19
|
readonly declarations?: PropertiesHyphen;
|
|
20
20
|
readonly layer: Layer;
|
|
21
|
-
readonly
|
|
22
|
-
animationNames?: string
|
|
23
|
-
variableNames?: string
|
|
21
|
+
readonly valid: boolean;
|
|
22
|
+
animationNames?: Set<string>;
|
|
23
|
+
variableNames?: Set<string>;
|
|
24
24
|
constructor(name: string, css: MasterCSS, registeredSyntax: DefinedRule, fixedClass?: string | undefined, mode?: string);
|
|
25
|
-
|
|
25
|
+
get text(): string;
|
|
26
|
+
get selectorText(): string;
|
|
26
27
|
resolveValue: (valueComponents: ValueComponent[], unit: string, bypassVariableNames: string[], bypassParsing: boolean) => string;
|
|
27
28
|
parseValues: (currentValueComponents: ValueComponent[], i: number, value: string, unit: string, endSymbol: string, parentFunctionName?: string, bypassParsing?: boolean, bypassVariableNames?: string[]) => number;
|
|
28
|
-
parseValue(token: string | number, unit?: any):
|
|
29
|
-
value: string;
|
|
30
|
-
type: 'string';
|
|
31
|
-
} | {
|
|
32
|
-
value: number;
|
|
33
|
-
unit: string;
|
|
34
|
-
type: 'number';
|
|
35
|
-
};
|
|
29
|
+
parseValue(token: string | number, unit?: any): import(".").StringValueComponent | NumberValueComponent;
|
|
36
30
|
get key(): string;
|
|
37
31
|
}
|
|
38
32
|
export interface SyntaxRule extends DefinedRule {
|
|
39
33
|
token: string;
|
|
40
|
-
|
|
41
|
-
vendorSuffixSelectors: Record<string, string[]>;
|
|
34
|
+
selectorNodes?: SelectorNode[];
|
|
42
35
|
important: boolean;
|
|
43
36
|
direction: string;
|
|
44
37
|
mode: string;
|