@master/css 2.0.0-rc.24 → 2.0.0-rc.26
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 +4 -4
- package/dist/config/index.d.ts +4 -4
- package/dist/config/index.mjs +4 -4
- package/dist/config/queries.cjs +13 -0
- package/dist/config/queries.d.ts +18 -0
- package/dist/config/queries.mjs +11 -0
- package/dist/config/variables.d.ts +0 -12
- package/dist/config/variables.mjs +2 -2
- package/dist/core.cjs +80 -75
- package/dist/core.d.ts +4 -4
- package/dist/core.mjs +76 -71
- package/dist/functions/are-rule-modes-equal.cjs +7 -0
- package/dist/functions/are-rule-modes-equal.d.ts +2 -0
- package/dist/functions/are-rule-modes-equal.mjs +5 -0
- package/dist/functions/are-rule-queries-equal.cjs +22 -0
- package/dist/functions/are-rule-queries-equal.d.ts +2 -0
- package/dist/functions/are-rule-queries-equal.mjs +20 -0
- package/dist/functions/are-rule-selectors-equal.cjs +29 -0
- package/dist/functions/are-rule-selectors-equal.d.ts +2 -0
- package/dist/functions/are-rule-selectors-equal.mjs +27 -0
- package/dist/functions/are-rule-states-equal.cjs +11 -0
- package/dist/functions/are-rule-states-equal.d.ts +2 -0
- package/dist/functions/are-rule-states-equal.mjs +9 -0
- package/dist/functions/are-rules-duplicated.cjs +17 -0
- package/dist/functions/are-rules-duplicated.d.ts +2 -0
- package/dist/functions/are-rules-duplicated.mjs +15 -0
- package/dist/{utils → functions}/extend-config.cjs +27 -14
- package/dist/functions/extend-config.d.ts +2 -0
- package/dist/{utils → functions}/extend-config.mjs +27 -14
- package/dist/functions/reorder-for-readable-classes.cjs +7 -7
- package/dist/functions/reorder-for-readable-classes.mjs +7 -7
- package/dist/index.cjs +16 -6
- package/dist/index.d.ts +7 -2
- package/dist/index.mjs +8 -3
- package/dist/rule.cjs +118 -90
- package/dist/rule.d.ts +28 -3
- package/dist/rule.mjs +118 -90
- package/dist/tokens/screen-sizes.cjs +2 -2
- package/dist/tokens/screen-sizes.mjs +2 -2
- 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/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/extend-config.d.ts +0 -2
|
@@ -17,18 +17,12 @@ function extendConfig(...configs) {
|
|
|
17
17
|
};
|
|
18
18
|
if (clonedConfig.styles) {
|
|
19
19
|
formatDeeply(clonedConfig.styles);
|
|
20
|
-
} else {
|
|
21
|
-
clonedConfig.styles = {};
|
|
22
20
|
}
|
|
23
|
-
if (clonedConfig.
|
|
24
|
-
formatDeeply(clonedConfig.
|
|
25
|
-
} else {
|
|
26
|
-
clonedConfig.mediaQueries = {};
|
|
21
|
+
if (clonedConfig.queries) {
|
|
22
|
+
formatDeeply(clonedConfig.queries);
|
|
27
23
|
}
|
|
28
24
|
if (clonedConfig.variables) {
|
|
29
25
|
formatDeeply(clonedConfig.variables);
|
|
30
|
-
} else {
|
|
31
|
-
clonedConfig.variables = {};
|
|
32
26
|
}
|
|
33
27
|
return clonedConfig;
|
|
34
28
|
};
|
|
@@ -43,15 +37,34 @@ function extendConfig(...configs) {
|
|
|
43
37
|
formattedConfigs.push(formatConfig(config));
|
|
44
38
|
})(eachConfig);
|
|
45
39
|
}
|
|
46
|
-
let extendedConfig =
|
|
47
|
-
|
|
40
|
+
let extendedConfig = {
|
|
41
|
+
animations: {},
|
|
42
|
+
styles: {},
|
|
43
|
+
queries: {},
|
|
44
|
+
variables: {}
|
|
45
|
+
};
|
|
46
|
+
for(let i = 0; i < formattedConfigs.length; i++){
|
|
48
47
|
const currentFormattedConfig = formattedConfigs[i];
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
for(const key in currentFormattedConfig){
|
|
49
|
+
switch(key){
|
|
50
|
+
case 'animations':
|
|
51
|
+
if (currentFormattedConfig.animations) {
|
|
52
|
+
Object.assign(extendedConfig.animations, currentFormattedConfig.animations);
|
|
53
|
+
}
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
if (currentFormattedConfig[key]) {
|
|
57
|
+
extendedConfig = extend(extendedConfig, {
|
|
58
|
+
[key]: currentFormattedConfig[key]
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// if (Object.prototype.hasOwnProperty.call(currentFormattedConfig.styles, key)) {
|
|
63
|
+
// Object.assign(extendedConfig.styles[key], currentFormattedConfig.styles[key])
|
|
64
|
+
// }
|
|
52
65
|
}
|
|
53
66
|
}
|
|
54
67
|
return extendedConfig;
|
|
55
68
|
}
|
|
56
69
|
|
|
57
|
-
export { extendConfig };
|
|
70
|
+
export { extendConfig as default };
|
|
@@ -32,26 +32,26 @@ var core = require('../core.cjs');
|
|
|
32
32
|
// 檢查 vendorSuffixSelectors 是否存在
|
|
33
33
|
const aHasVendorSuffix = a.vendorSuffixSelectors?.['']?.[0];
|
|
34
34
|
const bHasVendorSuffix = b.vendorSuffixSelectors?.['']?.[0];
|
|
35
|
-
// 檢查 media.token 是否存在
|
|
36
|
-
const aHasMediaToken = a.media?.token;
|
|
37
|
-
const bHasMediaToken = b.media?.token;
|
|
38
35
|
if (a.priority === -1 && b.priority === -1) {
|
|
39
36
|
// 如果 a 和 b 都有 vendorSuffixSelectors 或 media.token,則按照以下規則排序
|
|
40
37
|
if (aHasVendorSuffix && bHasVendorSuffix) {
|
|
41
38
|
return aHasVendorSuffix.localeCompare(bHasVendorSuffix);
|
|
42
39
|
}
|
|
40
|
+
// 檢查 media.token 是否存在
|
|
41
|
+
const aAtToke = a.atToken;
|
|
42
|
+
const bAtToken = b.atToken;
|
|
43
43
|
// 如果 a 和 b 都有 media.token 且不包含內建已處理過排序的,則按照以下規則排序
|
|
44
|
-
if (
|
|
45
|
-
return
|
|
44
|
+
if (aAtToke && bAtToken && !a.at.media?.find(({ name })=>name === 'min-width' || name === 'max-width') && !b.at.media?.find(({ name })=>name === 'min-width' || name === 'max-width')) {
|
|
45
|
+
return aAtToke.localeCompare(bAtToken);
|
|
46
46
|
}
|
|
47
47
|
if (aHasVendorSuffix && !bHasVendorSuffix) {
|
|
48
48
|
return 1;
|
|
49
49
|
} else if (!aHasVendorSuffix && bHasVendorSuffix) {
|
|
50
50
|
return -1;
|
|
51
51
|
}
|
|
52
|
-
if (
|
|
52
|
+
if (aAtToke && !bAtToken) {
|
|
53
53
|
return 1;
|
|
54
|
-
} else if (!
|
|
54
|
+
} else if (!aAtToke && bAtToken) {
|
|
55
55
|
return -1;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -30,26 +30,26 @@ import MasterCSS from '../core.mjs';
|
|
|
30
30
|
// 檢查 vendorSuffixSelectors 是否存在
|
|
31
31
|
const aHasVendorSuffix = a.vendorSuffixSelectors?.['']?.[0];
|
|
32
32
|
const bHasVendorSuffix = b.vendorSuffixSelectors?.['']?.[0];
|
|
33
|
-
// 檢查 media.token 是否存在
|
|
34
|
-
const aHasMediaToken = a.media?.token;
|
|
35
|
-
const bHasMediaToken = b.media?.token;
|
|
36
33
|
if (a.priority === -1 && b.priority === -1) {
|
|
37
34
|
// 如果 a 和 b 都有 vendorSuffixSelectors 或 media.token,則按照以下規則排序
|
|
38
35
|
if (aHasVendorSuffix && bHasVendorSuffix) {
|
|
39
36
|
return aHasVendorSuffix.localeCompare(bHasVendorSuffix);
|
|
40
37
|
}
|
|
38
|
+
// 檢查 media.token 是否存在
|
|
39
|
+
const aAtToke = a.atToken;
|
|
40
|
+
const bAtToken = b.atToken;
|
|
41
41
|
// 如果 a 和 b 都有 media.token 且不包含內建已處理過排序的,則按照以下規則排序
|
|
42
|
-
if (
|
|
43
|
-
return
|
|
42
|
+
if (aAtToke && bAtToken && !a.at.media?.find(({ name })=>name === 'min-width' || name === 'max-width') && !b.at.media?.find(({ name })=>name === 'min-width' || name === 'max-width')) {
|
|
43
|
+
return aAtToke.localeCompare(bAtToken);
|
|
44
44
|
}
|
|
45
45
|
if (aHasVendorSuffix && !bHasVendorSuffix) {
|
|
46
46
|
return 1;
|
|
47
47
|
} else if (!aHasVendorSuffix && bHasVendorSuffix) {
|
|
48
48
|
return -1;
|
|
49
49
|
}
|
|
50
|
-
if (
|
|
50
|
+
if (aAtToke && !bAtToken) {
|
|
51
51
|
return 1;
|
|
52
|
-
} else if (!
|
|
52
|
+
} else if (!aAtToke && bAtToken) {
|
|
53
53
|
return -1;
|
|
54
54
|
}
|
|
55
55
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -5,16 +5,21 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var index = require('./config/index.cjs');
|
|
6
6
|
var rule = require('./rule.cjs');
|
|
7
7
|
var layer = require('./layer.cjs');
|
|
8
|
-
var extend = require('@techor/extend');
|
|
9
|
-
var reorderForReadableClasses = require('./functions/reorder-for-readable-classes.cjs');
|
|
10
8
|
var core = require('./core.cjs');
|
|
9
|
+
var extendConfig = require('./functions/extend-config.cjs');
|
|
10
|
+
var reorderForReadableClasses = require('./functions/reorder-for-readable-classes.cjs');
|
|
11
|
+
var areRuleModesEqual = require('./functions/are-rule-modes-equal.cjs');
|
|
12
|
+
var areRuleQueriesEqual = require('./functions/are-rule-queries-equal.cjs');
|
|
13
|
+
var areRuleSelectorsEqual = require('./functions/are-rule-selectors-equal.cjs');
|
|
14
|
+
var areRuleStatesEqual = require('./functions/are-rule-states-equal.cjs');
|
|
15
|
+
var areRulesDuplicated = require('./functions/are-rules-duplicated.cjs');
|
|
16
|
+
var queries = require('./config/queries.cjs');
|
|
11
17
|
var selectors = require('./config/selectors.cjs');
|
|
12
18
|
var semantics = require('./config/semantics.cjs');
|
|
13
19
|
var rules = require('./config/rules.cjs');
|
|
14
20
|
var functions = require('./config/functions.cjs');
|
|
15
21
|
var animations = require('./config/animations.cjs');
|
|
16
22
|
var variables = require('./config/variables.cjs');
|
|
17
|
-
var screenSizes = require('./tokens/screen-sizes.cjs');
|
|
18
23
|
|
|
19
24
|
|
|
20
25
|
|
|
@@ -24,14 +29,19 @@ Object.defineProperty(exports, "Layer", {
|
|
|
24
29
|
enumerable: true,
|
|
25
30
|
get: function () { return layer.Layer; }
|
|
26
31
|
});
|
|
27
|
-
exports.extend = extend;
|
|
28
|
-
exports.reorderForReadableClasses = reorderForReadableClasses;
|
|
29
32
|
exports.MasterCSS = core.default;
|
|
30
33
|
exports.default = core.default;
|
|
34
|
+
exports.extendConfig = extendConfig;
|
|
35
|
+
exports.reorderForReadableClasses = reorderForReadableClasses;
|
|
36
|
+
exports.areRuleModesEqual = areRuleModesEqual;
|
|
37
|
+
exports.areRuleQueriesEqual = areRuleQueriesEqual;
|
|
38
|
+
exports.areRuleSelectorsEqual = areRuleSelectorsEqual;
|
|
39
|
+
exports.areRuleStatesEqual = areRuleStatesEqual;
|
|
40
|
+
exports.areRulesDuplicated = areRulesDuplicated;
|
|
41
|
+
exports.queries = queries;
|
|
31
42
|
exports.selectors = selectors;
|
|
32
43
|
exports.semantics = semantics;
|
|
33
44
|
exports.rules = rules.default;
|
|
34
45
|
exports.functions = functions;
|
|
35
46
|
exports.animations = animations;
|
|
36
47
|
exports.variables = variables;
|
|
37
|
-
exports.mediaQueries = screenSizes;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
export * from './config';
|
|
2
2
|
export { Rule } from './rule';
|
|
3
3
|
export { Layer } from './layer';
|
|
4
|
-
export { default as extend } from '@techor/extend';
|
|
5
|
-
export { default as reorderForReadableClasses } from './functions/reorder-for-readable-classes';
|
|
6
4
|
export { default as MasterCSS, default } from './core';
|
|
5
|
+
export { default as extendConfig } from './functions/extend-config';
|
|
6
|
+
export { default as reorderForReadableClasses } from './functions/reorder-for-readable-classes';
|
|
7
|
+
export { default as areRuleModesEqual } from './functions/are-rule-modes-equal';
|
|
8
|
+
export { default as areRuleQueriesEqual } from './functions/are-rule-queries-equal';
|
|
9
|
+
export { default as areRuleSelectorsEqual } from './functions/are-rule-selectors-equal';
|
|
10
|
+
export { default as areRuleStatesEqual } from './functions/are-rule-states-equal';
|
|
11
|
+
export { default as areRulesDuplicated } from './functions/are-rules-duplicated';
|
|
7
12
|
export type { NativeRule, MediaFeatureComponent, MediaQuery } from './rule';
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
export { config } from './config/index.mjs';
|
|
2
2
|
export { Rule } from './rule.mjs';
|
|
3
3
|
export { Layer } from './layer.mjs';
|
|
4
|
-
export { default as extend } from '@techor/extend';
|
|
5
|
-
export { default as reorderForReadableClasses } from './functions/reorder-for-readable-classes.mjs';
|
|
6
4
|
export { default as MasterCSS, default } from './core.mjs';
|
|
5
|
+
export { default as extendConfig } from './functions/extend-config.mjs';
|
|
6
|
+
export { default as reorderForReadableClasses } from './functions/reorder-for-readable-classes.mjs';
|
|
7
|
+
export { default as areRuleModesEqual } from './functions/are-rule-modes-equal.mjs';
|
|
8
|
+
export { default as areRuleQueriesEqual } from './functions/are-rule-queries-equal.mjs';
|
|
9
|
+
export { default as areRuleSelectorsEqual } from './functions/are-rule-selectors-equal.mjs';
|
|
10
|
+
export { default as areRuleStatesEqual } from './functions/are-rule-states-equal.mjs';
|
|
11
|
+
export { default as areRulesDuplicated } from './functions/are-rules-duplicated.mjs';
|
|
12
|
+
export { default as queries } from './config/queries.mjs';
|
|
7
13
|
export { default as selectors } from './config/selectors.mjs';
|
|
8
14
|
export { default as semantics } from './config/semantics.mjs';
|
|
9
15
|
export { default as rules } from './config/rules.mjs';
|
|
10
16
|
export { default as functions } from './config/functions.mjs';
|
|
11
17
|
export { default as animations } from './config/animations.mjs';
|
|
12
18
|
export { default as variables } from './config/variables.mjs';
|
|
13
|
-
export { default as mediaQueries } from './tokens/screen-sizes.mjs';
|
package/dist/rule.cjs
CHANGED
|
@@ -5,7 +5,6 @@ var cssEscape = require('./shared/utils/css-escape.cjs');
|
|
|
5
5
|
var layer = require('./layer.cjs');
|
|
6
6
|
var baseUnitRegex = require('./constants/base-unit-regex.cjs');
|
|
7
7
|
|
|
8
|
-
const atRuleRegExp = /^(media|supports|page|font-face|keyframes|counter-style|font-feature-values|property|layer|container)(?=\||{|\(|$)/;
|
|
9
8
|
class Rule {
|
|
10
9
|
className;
|
|
11
10
|
css;
|
|
@@ -14,6 +13,7 @@ class Rule {
|
|
|
14
13
|
natives;
|
|
15
14
|
order;
|
|
16
15
|
layer;
|
|
16
|
+
atToken;
|
|
17
17
|
stateToken;
|
|
18
18
|
declarations;
|
|
19
19
|
animationNames;
|
|
@@ -26,6 +26,7 @@ class Rule {
|
|
|
26
26
|
this.natives = [];
|
|
27
27
|
this.order = 0;
|
|
28
28
|
this.layer = 0;
|
|
29
|
+
this.atToken = '';
|
|
29
30
|
this.resolveValue = (valueComponents, unit, bypassVariableNames, bypassParsing)=>{
|
|
30
31
|
const { functions } = this.css.config;
|
|
31
32
|
let currentValue = '';
|
|
@@ -47,9 +48,9 @@ class Rule {
|
|
|
47
48
|
const variable = this.css.variables[eachValueComponent.name];
|
|
48
49
|
if (variable) {
|
|
49
50
|
const handleVariable = (normalHandler, varHandler)=>{
|
|
50
|
-
if (variable.
|
|
51
|
-
if (this.
|
|
52
|
-
const themeVariable = variable.
|
|
51
|
+
if (variable.modes) {
|
|
52
|
+
if (this.mode) {
|
|
53
|
+
const themeVariable = variable.modes[this.mode] ?? variable;
|
|
53
54
|
if (themeVariable?.value) {
|
|
54
55
|
normalHandler(themeVariable);
|
|
55
56
|
}
|
|
@@ -264,8 +265,8 @@ class Rule {
|
|
|
264
265
|
if (!definition.separators) definition.separators = [
|
|
265
266
|
','
|
|
266
267
|
];
|
|
267
|
-
const { scope, important,
|
|
268
|
-
const { selectors,
|
|
268
|
+
const { scope, important, modeDriver } = css.config;
|
|
269
|
+
const { selectors, queries, stylesBy, animations } = css;
|
|
269
270
|
const classNames = stylesBy[className];
|
|
270
271
|
if (create) create.call(this, className);
|
|
271
272
|
// 1. value / selectorToken
|
|
@@ -451,109 +452,124 @@ class Rule {
|
|
|
451
452
|
for(let i = 1; i < stateTokens.length; i++){
|
|
452
453
|
const atToken = stateTokens[i];
|
|
453
454
|
if (atToken) {
|
|
455
|
+
this.atToken += '@' + atToken;
|
|
454
456
|
if (atToken === 'rtl' || atToken === 'ltr') {
|
|
455
457
|
this.direction = atToken;
|
|
456
458
|
} else {
|
|
457
|
-
let
|
|
458
|
-
|
|
459
|
-
|
|
459
|
+
let queryType;
|
|
460
|
+
const atComponents = [];
|
|
461
|
+
// x font-face, counter-style, keyframes, font-feature-values, property, layer
|
|
462
|
+
const queryTypeRegExp = /^(media|supports|container)/;
|
|
463
|
+
const atRuleResult = queryTypeRegExp.exec(atToken);
|
|
460
464
|
if (atRuleResult) {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
this.media = {
|
|
465
|
+
queryType = atRuleResult[1];
|
|
466
|
+
atComponents.push({
|
|
467
|
+
type: 'arbitrary',
|
|
465
468
|
token: atToken,
|
|
466
|
-
|
|
467
|
-
};
|
|
468
|
-
|
|
469
|
-
const analyzeToken = (
|
|
470
|
-
if (
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
469
|
+
value: atToken.slice(queryType.length).replace(/\|/g, ' ')
|
|
470
|
+
});
|
|
471
|
+
} else {
|
|
472
|
+
const analyzeToken = (atComponentToken)=>{
|
|
473
|
+
if (atComponentToken === 'all' || atComponentToken === 'print' || atComponentToken === 'screen' || atComponentToken === 'speech') {
|
|
474
|
+
queryType = 'media';
|
|
475
|
+
atComponents.push({
|
|
476
|
+
type: 'media-type',
|
|
477
|
+
token: atComponentToken,
|
|
478
|
+
value: atComponentToken
|
|
479
|
+
});
|
|
480
|
+
} else if (atComponentToken === '&') {
|
|
481
|
+
atComponents.push({
|
|
482
|
+
type: 'operator',
|
|
483
|
+
token: atComponentToken,
|
|
484
|
+
value: 'and'
|
|
485
|
+
});
|
|
486
|
+
} else if (atComponentToken.startsWith('')) {
|
|
487
|
+
const targetQuery = queries[atComponentToken];
|
|
488
|
+
if (targetQuery && typeof targetQuery === 'string') {
|
|
489
|
+
const match = targetQuery.match(queryTypeRegExp);
|
|
490
|
+
queryType = match ? match[1] : '';
|
|
491
|
+
if (!queryType) throw new Error(`Invalid query '${atComponentToken}': '${targetQuery}'`);
|
|
492
|
+
atComponents.push({
|
|
493
|
+
type: 'arbitrary',
|
|
494
|
+
value: targetQuery.slice(match ? match[1].length + 1 : 0)
|
|
495
|
+
});
|
|
477
496
|
} else {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
497
|
+
// todo: container queries
|
|
498
|
+
queryType = 'media';
|
|
499
|
+
let featureName = '';
|
|
500
|
+
let extremumOperator = '';
|
|
501
|
+
let correction = 0;
|
|
502
|
+
if (atComponentToken.startsWith('<=')) {
|
|
503
|
+
extremumOperator = '<=';
|
|
504
|
+
featureName = 'max-width';
|
|
505
|
+
} else if (atComponentToken.startsWith('>=') || targetQuery) {
|
|
506
|
+
extremumOperator = '>=';
|
|
507
|
+
featureName = 'min-width';
|
|
508
|
+
} else if (atComponentToken.startsWith('>')) {
|
|
509
|
+
extremumOperator = '>';
|
|
510
|
+
featureName = 'min-width';
|
|
511
|
+
correction = .02;
|
|
512
|
+
} else if (atComponentToken.startsWith('<')) {
|
|
513
|
+
extremumOperator = '<';
|
|
514
|
+
featureName = 'max-width';
|
|
515
|
+
correction = -.02;
|
|
516
|
+
}
|
|
517
|
+
const token = extremumOperator ? atComponentToken.replace(extremumOperator, '') : atComponentToken;
|
|
518
|
+
const viewport = queries[token];
|
|
519
|
+
switch(featureName){
|
|
520
|
+
case 'max-width':
|
|
521
|
+
case 'min-width':
|
|
522
|
+
// eslint-disable-next-line no-case-declarations
|
|
523
|
+
if (typeof viewport === 'number') {
|
|
524
|
+
atComponents.push({
|
|
525
|
+
type: 'feature',
|
|
526
|
+
name: featureName,
|
|
527
|
+
valueType: 'number',
|
|
528
|
+
value: viewport + correction,
|
|
529
|
+
unit: 'px'
|
|
530
|
+
});
|
|
531
|
+
} else {
|
|
532
|
+
const valueComponent = this.parseValueComponent(token, 'px');
|
|
533
|
+
if (valueComponent.type === 'number') {
|
|
534
|
+
atComponents.push({
|
|
535
|
+
type: 'feature',
|
|
536
|
+
name: featureName,
|
|
537
|
+
valueType: 'number',
|
|
538
|
+
value: valueComponent.value + correction,
|
|
539
|
+
unit: valueComponent.unit
|
|
540
|
+
});
|
|
522
541
|
} else {
|
|
523
|
-
|
|
542
|
+
atComponents.push({
|
|
543
|
+
type: 'feature',
|
|
544
|
+
name: featureName,
|
|
545
|
+
valueType: 'string',
|
|
546
|
+
value: token
|
|
547
|
+
});
|
|
524
548
|
}
|
|
525
|
-
|
|
526
|
-
|
|
549
|
+
}
|
|
550
|
+
break;
|
|
527
551
|
}
|
|
528
552
|
}
|
|
529
553
|
}
|
|
530
554
|
};
|
|
531
555
|
const isAmpersandIncluded = atToken.includes('&');
|
|
532
556
|
if (isAmpersandIncluded) {
|
|
533
|
-
const typeOrFeatureTokens = atToken.split(
|
|
534
|
-
for (const
|
|
535
|
-
analyzeToken(
|
|
557
|
+
const typeOrFeatureTokens = atToken.split(/(&|,)/);
|
|
558
|
+
for (const atComponentToken of typeOrFeatureTokens){
|
|
559
|
+
analyzeToken(atComponentToken);
|
|
536
560
|
}
|
|
537
561
|
} else {
|
|
538
562
|
analyzeToken(atToken);
|
|
539
563
|
}
|
|
540
|
-
if (
|
|
541
|
-
queryText = this.media.type;
|
|
542
|
-
}
|
|
543
|
-
if (queryTexts.length) {
|
|
544
|
-
queryText = queryTexts.join(' and ');
|
|
545
|
-
}
|
|
546
|
-
if (!queryText) {
|
|
564
|
+
if (!atComponents.length) {
|
|
547
565
|
if (!isAmpersandIncluded) {
|
|
548
|
-
this.
|
|
566
|
+
this.mode = atToken;
|
|
549
567
|
continue;
|
|
550
568
|
}
|
|
551
|
-
} else {
|
|
552
|
-
type = 'media';
|
|
553
569
|
}
|
|
554
570
|
}
|
|
555
|
-
if (
|
|
556
|
-
this.at[
|
|
571
|
+
if (queryType) {
|
|
572
|
+
this.at[queryType] = atComponents;
|
|
557
573
|
}
|
|
558
574
|
}
|
|
559
575
|
}
|
|
@@ -612,7 +628,7 @@ class Rule {
|
|
|
612
628
|
const prefixSelectors = this.vendorPrefixSelectors[prefixSelectorVendor];
|
|
613
629
|
const suffixSelectors = this.vendorSuffixSelectors[eachSuffixSelectorVendor];
|
|
614
630
|
const prefixTexts = prefixSelectors.map((eachPrefixSelector)=>eachPrefixSelector + prefixText);
|
|
615
|
-
const getCssText = (name)=>prefixTexts.map((eachPrefixText)=>(this.
|
|
631
|
+
const getCssText = (name)=>prefixTexts.map((eachPrefixText)=>(this.mode && modeDriver !== 'media' ? modeDriver === 'host' ? `:host(.${this.mode}) ` : `.${this.mode} ` : '') + (scope ? scope + ' ' : '') + eachPrefixText).reduce((arr, eachPrefixText)=>{
|
|
616
632
|
arr.push(suffixSelectors.reduce((_arr, eachSuffixSelector)=>{
|
|
617
633
|
_arr.push(eachPrefixText + '.' + cssEscape(name) + eachSuffixSelector);
|
|
618
634
|
return _arr;
|
|
@@ -621,10 +637,10 @@ class Rule {
|
|
|
621
637
|
}, []).join(',');
|
|
622
638
|
let cssText = getCssText(className) + (classNames ? classNames.reduce((str, className)=>str + ',' + getCssText(className), '') : '') + '{' + propertiesText.join(';') + '}';
|
|
623
639
|
for (const key of Object.keys(this.at).sort((_a, b)=>b === 'supports' ? -1 : 1)){
|
|
624
|
-
cssText = '@' + key + (key.includes(' ') ? '' : ' ') + this.at[key] + '{' + cssText + '}';
|
|
640
|
+
cssText = '@' + key + (key.includes(' ') ? '' : ' ') + this.at[key].map((eachAtComponent)=>this.resolveAtComponent(eachAtComponent)).join(' ') + '{' + cssText + '}';
|
|
625
641
|
}
|
|
626
|
-
if (this.
|
|
627
|
-
cssText = `@media(prefers-color-scheme:${this.
|
|
642
|
+
if (this.mode && modeDriver === 'media') {
|
|
643
|
+
cssText = `@media(prefers-color-scheme:${this.mode}){` + cssText + '}';
|
|
628
644
|
}
|
|
629
645
|
this.natives.push({
|
|
630
646
|
text: cssText
|
|
@@ -633,6 +649,18 @@ class Rule {
|
|
|
633
649
|
}
|
|
634
650
|
}
|
|
635
651
|
}
|
|
652
|
+
resolveAtComponent(atComponent) {
|
|
653
|
+
switch(atComponent.type){
|
|
654
|
+
case 'arbitrary':
|
|
655
|
+
return atComponent.value;
|
|
656
|
+
case 'media-type':
|
|
657
|
+
return atComponent.value;
|
|
658
|
+
case 'feature':
|
|
659
|
+
return '(' + atComponent.name + ':' + atComponent.value + (atComponent.unit || '') + ')';
|
|
660
|
+
case 'operator':
|
|
661
|
+
return atComponent.value;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
636
664
|
resolveValue;
|
|
637
665
|
get text() {
|
|
638
666
|
return this.natives.map((eachNative)=>eachNative.text).join('');
|
package/dist/rule.d.ts
CHANGED
|
@@ -4,21 +4,47 @@ import { type PropertiesHyphen } from 'csstype';
|
|
|
4
4
|
export declare class Rule {
|
|
5
5
|
readonly className: string;
|
|
6
6
|
css: MasterCSS;
|
|
7
|
-
readonly at: Record<string,
|
|
7
|
+
readonly at: Record<string, AtComponent[]>;
|
|
8
8
|
readonly priority: number;
|
|
9
9
|
readonly natives: NativeRule[];
|
|
10
10
|
readonly order: number;
|
|
11
11
|
readonly layer: Layer;
|
|
12
|
+
readonly atToken: string;
|
|
12
13
|
readonly stateToken: string;
|
|
13
14
|
readonly declarations?: PropertiesHyphen;
|
|
14
15
|
animationNames?: string[];
|
|
15
16
|
variableNames?: string[];
|
|
16
17
|
constructor(className: string, RegisteredRule: RegisteredRule, css: MasterCSS);
|
|
18
|
+
resolveAtComponent(atComponent: AtComponent): string;
|
|
17
19
|
resolveValue: (valueComponents: ValueComponent[], unit: string, bypassVariableNames: string[], bypassParsing: boolean) => string;
|
|
18
20
|
get text(): string;
|
|
19
21
|
parseValue: (currentValueComponents: ValueComponent[], i: number, value: string, unit: string, endSymbol: string, parentFunctionName?: string, bypassParsing?: boolean, bypassVariableNames?: string[]) => number;
|
|
20
22
|
parseValueComponent(token: string | number, unit?: any): StringValueComponent | NumericValueComponent;
|
|
21
23
|
}
|
|
24
|
+
export type AtComponent = AtArbitraryComponent | AtMediaTypeComponent | AtFeatureComponent | AtOperatorComponent;
|
|
25
|
+
export interface AtArbitraryComponent {
|
|
26
|
+
type: 'arbitrary';
|
|
27
|
+
token?: string;
|
|
28
|
+
value: string;
|
|
29
|
+
}
|
|
30
|
+
export interface AtMediaTypeComponent {
|
|
31
|
+
type: 'media-type';
|
|
32
|
+
token?: string;
|
|
33
|
+
value: 'all' | 'print' | 'screen' | 'speech';
|
|
34
|
+
}
|
|
35
|
+
export interface AtFeatureComponent {
|
|
36
|
+
type: 'feature';
|
|
37
|
+
token?: string;
|
|
38
|
+
name: string;
|
|
39
|
+
valueType: 'number' | 'string';
|
|
40
|
+
value: string | number;
|
|
41
|
+
unit?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface AtOperatorComponent {
|
|
44
|
+
type: 'operator';
|
|
45
|
+
token: '&';
|
|
46
|
+
value: 'and';
|
|
47
|
+
}
|
|
22
48
|
export type ValueComponent = StringValueComponent | NumericValueComponent | FunctionValueComponent | VariableValueComponent | SeparatorValueComponent;
|
|
23
49
|
export interface StringValueComponent {
|
|
24
50
|
text?: string;
|
|
@@ -63,9 +89,8 @@ export interface Rule extends RegisteredRule {
|
|
|
63
89
|
vendorPrefixSelectors: Record<string, string[]>;
|
|
64
90
|
vendorSuffixSelectors: Record<string, string[]>;
|
|
65
91
|
important: boolean;
|
|
66
|
-
media: MediaQuery;
|
|
67
92
|
direction: string;
|
|
68
|
-
|
|
93
|
+
mode: string;
|
|
69
94
|
unitToken: string;
|
|
70
95
|
hasWhere: boolean;
|
|
71
96
|
valueComponents: Array<ValueComponent>;
|