@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/rule-node.cjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
class Rule {
|
|
4
|
-
name;
|
|
5
|
-
nodes;
|
|
6
|
-
constructor(name, nodes = []){
|
|
7
|
-
this.name = name;
|
|
8
|
-
this.nodes = nodes;
|
|
9
|
-
}
|
|
10
|
-
get key() {
|
|
11
|
-
return this.name;
|
|
12
|
-
}
|
|
13
|
-
get text() {
|
|
14
|
-
return this.nodes.map(({ text })=>text).join('');
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
exports.Rule = Rule;
|
package/dist/rule-node.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare class Rule {
|
|
2
|
-
readonly name: string;
|
|
3
|
-
nodes: RuleNode[];
|
|
4
|
-
constructor(name: string, nodes?: RuleNode[]);
|
|
5
|
-
get key(): string;
|
|
6
|
-
get text(): string;
|
|
7
|
-
}
|
|
8
|
-
export interface RuleNode {
|
|
9
|
-
text: string;
|
|
10
|
-
selectorText?: string;
|
|
11
|
-
native?: CSSRule;
|
|
12
|
-
suffixSelectors?: string[];
|
|
13
|
-
prefixSelectors?: string[];
|
|
14
|
-
}
|
package/dist/rule-node.mjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
class Rule {
|
|
2
|
-
name;
|
|
3
|
-
nodes;
|
|
4
|
-
constructor(name, nodes = []){
|
|
5
|
-
this.name = name;
|
|
6
|
-
this.nodes = nodes;
|
|
7
|
-
}
|
|
8
|
-
get key() {
|
|
9
|
-
return this.name;
|
|
10
|
-
}
|
|
11
|
-
get text() {
|
|
12
|
-
return this.nodes.map(({ text })=>text).join('');
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export { Rule };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function areRuleAtEqual(a, b) {
|
|
4
|
-
const compare = (aList, bList)=>{
|
|
5
|
-
const aResolved = (aList ?? []).map(a.resolveAtComponent);
|
|
6
|
-
const bResolved = (bList ?? []).map(b.resolveAtComponent);
|
|
7
|
-
return aResolved.length === bResolved.length && aResolved.every((val)=>bResolved.includes(val)) && bResolved.every((val)=>aResolved.includes(val));
|
|
8
|
-
};
|
|
9
|
-
return compare(a.mediaAtComponents, b.mediaAtComponents) && compare(a.supportsAtComponents, b.supportsAtComponents) && compare(a.containerAtComponents, b.containerAtComponents) && compare(a.layerAtComponents, b.layerAtComponents);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
module.exports = areRuleAtEqual;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
function areRuleAtEqual(a, b) {
|
|
2
|
-
const compare = (aList, bList)=>{
|
|
3
|
-
const aResolved = (aList ?? []).map(a.resolveAtComponent);
|
|
4
|
-
const bResolved = (bList ?? []).map(b.resolveAtComponent);
|
|
5
|
-
return aResolved.length === bResolved.length && aResolved.every((val)=>bResolved.includes(val)) && bResolved.every((val)=>aResolved.includes(val));
|
|
6
|
-
};
|
|
7
|
-
return compare(a.mediaAtComponents, b.mediaAtComponents) && compare(a.supportsAtComponents, b.supportsAtComponents) && compare(a.containerAtComponents, b.containerAtComponents) && compare(a.layerAtComponents, b.layerAtComponents);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export { areRuleAtEqual as default };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function areRuleSelectorsEqual(aSyntaxRule, bSyntaxRule) {
|
|
4
|
-
// suffix
|
|
5
|
-
const aVendorSuffixSelectorKeys = aSyntaxRule.vendorSuffixSelectors ? Object.keys(aSyntaxRule.vendorSuffixSelectors) : [];
|
|
6
|
-
const bVendorSuffixSelectorKeys = bSyntaxRule.vendorSuffixSelectors ? Object.keys(bSyntaxRule.vendorSuffixSelectors) : [];
|
|
7
|
-
if (aVendorSuffixSelectorKeys.length !== bVendorSuffixSelectorKeys.length) return false;
|
|
8
|
-
const isSameVendorSuffixSelectors = aVendorSuffixSelectorKeys.every((eachAKey)=>{
|
|
9
|
-
if (!Object.prototype.hasOwnProperty.call(bSyntaxRule.vendorSuffixSelectors, eachAKey)) return false;
|
|
10
|
-
const aValues = aSyntaxRule.vendorSuffixSelectors[eachAKey];
|
|
11
|
-
const bValues = bSyntaxRule.vendorSuffixSelectors[eachAKey];
|
|
12
|
-
return aValues.length === bValues.length && aValues.every((eachAValue)=>bValues.includes(eachAValue));
|
|
13
|
-
});
|
|
14
|
-
if (!isSameVendorSuffixSelectors) return false;
|
|
15
|
-
// prefix
|
|
16
|
-
const aVendorPrefixSelectorKeys = aSyntaxRule.vendorPrefixSelectors ? Object.keys(aSyntaxRule.vendorPrefixSelectors) : [];
|
|
17
|
-
const bVendorPrefixSelectorKeys = bSyntaxRule.vendorPrefixSelectors ? Object.keys(bSyntaxRule.vendorPrefixSelectors) : [];
|
|
18
|
-
if (aVendorPrefixSelectorKeys.length !== bVendorPrefixSelectorKeys.length) return false;
|
|
19
|
-
const isSameVendorPrefixSelectors = aVendorPrefixSelectorKeys.every((eachAKey)=>{
|
|
20
|
-
if (!Object.prototype.hasOwnProperty.call(bSyntaxRule.vendorPrefixSelectors, eachAKey)) return false;
|
|
21
|
-
const aValues = aSyntaxRule.vendorPrefixSelectors?.[eachAKey] || [];
|
|
22
|
-
const bValues = bSyntaxRule.vendorPrefixSelectors?.[eachAKey] || [];
|
|
23
|
-
return aValues.length === bValues.length && aValues.every((eachAValue)=>bValues.includes(eachAValue));
|
|
24
|
-
});
|
|
25
|
-
if (!isSameVendorPrefixSelectors) return false;
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = areRuleSelectorsEqual;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
function areRuleSelectorsEqual(aSyntaxRule, bSyntaxRule) {
|
|
2
|
-
// suffix
|
|
3
|
-
const aVendorSuffixSelectorKeys = aSyntaxRule.vendorSuffixSelectors ? Object.keys(aSyntaxRule.vendorSuffixSelectors) : [];
|
|
4
|
-
const bVendorSuffixSelectorKeys = bSyntaxRule.vendorSuffixSelectors ? Object.keys(bSyntaxRule.vendorSuffixSelectors) : [];
|
|
5
|
-
if (aVendorSuffixSelectorKeys.length !== bVendorSuffixSelectorKeys.length) return false;
|
|
6
|
-
const isSameVendorSuffixSelectors = aVendorSuffixSelectorKeys.every((eachAKey)=>{
|
|
7
|
-
if (!Object.prototype.hasOwnProperty.call(bSyntaxRule.vendorSuffixSelectors, eachAKey)) return false;
|
|
8
|
-
const aValues = aSyntaxRule.vendorSuffixSelectors[eachAKey];
|
|
9
|
-
const bValues = bSyntaxRule.vendorSuffixSelectors[eachAKey];
|
|
10
|
-
return aValues.length === bValues.length && aValues.every((eachAValue)=>bValues.includes(eachAValue));
|
|
11
|
-
});
|
|
12
|
-
if (!isSameVendorSuffixSelectors) return false;
|
|
13
|
-
// prefix
|
|
14
|
-
const aVendorPrefixSelectorKeys = aSyntaxRule.vendorPrefixSelectors ? Object.keys(aSyntaxRule.vendorPrefixSelectors) : [];
|
|
15
|
-
const bVendorPrefixSelectorKeys = bSyntaxRule.vendorPrefixSelectors ? Object.keys(bSyntaxRule.vendorPrefixSelectors) : [];
|
|
16
|
-
if (aVendorPrefixSelectorKeys.length !== bVendorPrefixSelectorKeys.length) return false;
|
|
17
|
-
const isSameVendorPrefixSelectors = aVendorPrefixSelectorKeys.every((eachAKey)=>{
|
|
18
|
-
if (!Object.prototype.hasOwnProperty.call(bSyntaxRule.vendorPrefixSelectors, eachAKey)) return false;
|
|
19
|
-
const aValues = aSyntaxRule.vendorPrefixSelectors?.[eachAKey] || [];
|
|
20
|
-
const bValues = bSyntaxRule.vendorPrefixSelectors?.[eachAKey] || [];
|
|
21
|
-
return aValues.length === bValues.length && aValues.every((eachAValue)=>bValues.includes(eachAValue));
|
|
22
|
-
});
|
|
23
|
-
if (!isSameVendorPrefixSelectors) return false;
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export { areRuleSelectorsEqual as default };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var areRuleSelectorsEqual = require('./are-rule-selectors-equal.cjs');
|
|
4
|
-
var areRuleModesEqual = require('./are-rule-modes-equal.cjs');
|
|
5
|
-
var areRuleAtEqual = require('./are-rule-at-equal.cjs');
|
|
6
|
-
|
|
7
|
-
function areRuleStatesEqual(aSyntaxRule, bSyntaxRule) {
|
|
8
|
-
return areRuleSelectorsEqual(aSyntaxRule, bSyntaxRule) && areRuleModesEqual(aSyntaxRule, bSyntaxRule) && areRuleAtEqual(aSyntaxRule, bSyntaxRule);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
module.exports = areRuleStatesEqual;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import areRuleSelectorsEqual from './are-rule-selectors-equal.mjs';
|
|
2
|
-
import areRuleModesEqual from './are-rule-modes-equal.mjs';
|
|
3
|
-
import areRuleAtEqual from './are-rule-at-equal.mjs';
|
|
4
|
-
|
|
5
|
-
function areRuleStatesEqual(aSyntaxRule, bSyntaxRule) {
|
|
6
|
-
return areRuleSelectorsEqual(aSyntaxRule, bSyntaxRule) && areRuleModesEqual(aSyntaxRule, bSyntaxRule) && areRuleAtEqual(aSyntaxRule, bSyntaxRule);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export { areRuleStatesEqual as default };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function areRulesDuplicated(aSyntaxRule, bSyntaxRule) {
|
|
4
|
-
const aKeys = Object.keys(aSyntaxRule.declarations || {});
|
|
5
|
-
const bKeys = Object.keys(bSyntaxRule.declarations || {});
|
|
6
|
-
if (aKeys.length !== bKeys.length) {
|
|
7
|
-
return false;
|
|
8
|
-
}
|
|
9
|
-
for (const key of aKeys){
|
|
10
|
-
if (!Object.prototype.hasOwnProperty.call(bSyntaxRule.declarations, key)) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
module.exports = areRulesDuplicated;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
function areRulesDuplicated(aSyntaxRule, bSyntaxRule) {
|
|
2
|
-
const aKeys = Object.keys(aSyntaxRule.declarations || {});
|
|
3
|
-
const bKeys = Object.keys(bSyntaxRule.declarations || {});
|
|
4
|
-
if (aKeys.length !== bKeys.length) {
|
|
5
|
-
return false;
|
|
6
|
-
}
|
|
7
|
-
for (const key of aKeys){
|
|
8
|
-
if (!Object.prototype.hasOwnProperty.call(bSyntaxRule.declarations, key)) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { areRulesDuplicated as default };
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var syntaxRuleType = require('../syntax-rule-type.cjs');
|
|
4
|
-
var core = require('../core.cjs');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Sorts classes in a consistent order
|
|
8
|
-
* @param classes
|
|
9
|
-
* @param options
|
|
10
|
-
* @returns consistent classes
|
|
11
|
-
*/ function reorderForReadableClasses(classes, css = new core()) {
|
|
12
|
-
css.add(...classes);
|
|
13
|
-
const orderedClasses = css.generalLayer.rules// 只保留樣式語法相關的 rules, 排除 keyframes 與 variables 在外
|
|
14
|
-
.filter((eachRule)=>eachRule.type).sort((a, b)=>{
|
|
15
|
-
if (a.type === syntaxRuleType.Utility && b.type !== syntaxRuleType.Utility) {
|
|
16
|
-
// 如果 a 是 SyntaxRuleType.Utility 而 b 不是,则 a 应该排在 b 前面
|
|
17
|
-
return -1;
|
|
18
|
-
} else if (a.type !== syntaxRuleType.Utility && b.type === syntaxRuleType.Utility) {
|
|
19
|
-
// 如果 b 是 SyntaxRuleType.Utility 而 a 不是,则 b 应该排在 a 前面
|
|
20
|
-
return 1;
|
|
21
|
-
} else if (a.id !== b.id) {
|
|
22
|
-
return a.name.localeCompare(b.name);
|
|
23
|
-
} else {
|
|
24
|
-
// 檢查 vendorSuffixSelectors 是否存在
|
|
25
|
-
const aHasVendorSuffix = a.vendorSuffixSelectors?.['']?.[0];
|
|
26
|
-
const bHasVendorSuffix = b.vendorSuffixSelectors?.['']?.[0];
|
|
27
|
-
if (a.priority === -1 && b.priority === -1) {
|
|
28
|
-
// 如果 a 和 b 都有 vendorSuffixSelectors 或 media.token,則按照以下規則排序
|
|
29
|
-
if (aHasVendorSuffix && bHasVendorSuffix) {
|
|
30
|
-
return aHasVendorSuffix.localeCompare(bHasVendorSuffix);
|
|
31
|
-
}
|
|
32
|
-
// 檢查 media.token 是否存在
|
|
33
|
-
const aAtToke = a.atToken;
|
|
34
|
-
const bAtToken = b.atToken;
|
|
35
|
-
// 如果 a 和 b 都有 media.token 且不包含內建已處理過排序的,則按照以下規則排序
|
|
36
|
-
if (aAtToke && bAtToken && a.mediaAtComponents && !a.mediaAtComponents.find(({ name })=>name === 'min-width' || name === 'max-width') && b.mediaAtComponents && !b.mediaAtComponents.find(({ name })=>name === 'min-width' || name === 'max-width')) {
|
|
37
|
-
return aAtToke.localeCompare(bAtToken);
|
|
38
|
-
}
|
|
39
|
-
if (aHasVendorSuffix && !bHasVendorSuffix) {
|
|
40
|
-
return 1;
|
|
41
|
-
} else if (!aHasVendorSuffix && bHasVendorSuffix) {
|
|
42
|
-
return -1;
|
|
43
|
-
}
|
|
44
|
-
if (aAtToke && !bAtToken) {
|
|
45
|
-
return 1;
|
|
46
|
-
} else if (!aAtToke && bAtToken) {
|
|
47
|
-
return -1;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// 如果 a 和 b 的 id 相同,則按照以下規則排序
|
|
51
|
-
if (a.id === b.id && a.stateToken === b.stateToken) {
|
|
52
|
-
return a.name.localeCompare(b.name);
|
|
53
|
-
}
|
|
54
|
-
// 再按照 rule.order 本身來升序排列
|
|
55
|
-
return a.order - b.order;
|
|
56
|
-
}
|
|
57
|
-
}).map((eachRule)=>eachRule.name);
|
|
58
|
-
css.remove(...classes);
|
|
59
|
-
return orderedClasses;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
module.exports = reorderForReadableClasses;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import SyntaxRuleType from '../syntax-rule-type.mjs';
|
|
2
|
-
import MasterCSS from '../core.mjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Sorts classes in a consistent order
|
|
6
|
-
* @param classes
|
|
7
|
-
* @param options
|
|
8
|
-
* @returns consistent classes
|
|
9
|
-
*/ function reorderForReadableClasses(classes, css = new MasterCSS()) {
|
|
10
|
-
css.add(...classes);
|
|
11
|
-
const orderedClasses = css.generalLayer.rules// 只保留樣式語法相關的 rules, 排除 keyframes 與 variables 在外
|
|
12
|
-
.filter((eachRule)=>eachRule.type).sort((a, b)=>{
|
|
13
|
-
if (a.type === SyntaxRuleType.Utility && b.type !== SyntaxRuleType.Utility) {
|
|
14
|
-
// 如果 a 是 SyntaxRuleType.Utility 而 b 不是,则 a 应该排在 b 前面
|
|
15
|
-
return -1;
|
|
16
|
-
} else if (a.type !== SyntaxRuleType.Utility && b.type === SyntaxRuleType.Utility) {
|
|
17
|
-
// 如果 b 是 SyntaxRuleType.Utility 而 a 不是,则 b 应该排在 a 前面
|
|
18
|
-
return 1;
|
|
19
|
-
} else if (a.id !== b.id) {
|
|
20
|
-
return a.name.localeCompare(b.name);
|
|
21
|
-
} else {
|
|
22
|
-
// 檢查 vendorSuffixSelectors 是否存在
|
|
23
|
-
const aHasVendorSuffix = a.vendorSuffixSelectors?.['']?.[0];
|
|
24
|
-
const bHasVendorSuffix = b.vendorSuffixSelectors?.['']?.[0];
|
|
25
|
-
if (a.priority === -1 && b.priority === -1) {
|
|
26
|
-
// 如果 a 和 b 都有 vendorSuffixSelectors 或 media.token,則按照以下規則排序
|
|
27
|
-
if (aHasVendorSuffix && bHasVendorSuffix) {
|
|
28
|
-
return aHasVendorSuffix.localeCompare(bHasVendorSuffix);
|
|
29
|
-
}
|
|
30
|
-
// 檢查 media.token 是否存在
|
|
31
|
-
const aAtToke = a.atToken;
|
|
32
|
-
const bAtToken = b.atToken;
|
|
33
|
-
// 如果 a 和 b 都有 media.token 且不包含內建已處理過排序的,則按照以下規則排序
|
|
34
|
-
if (aAtToke && bAtToken && a.mediaAtComponents && !a.mediaAtComponents.find(({ name })=>name === 'min-width' || name === 'max-width') && b.mediaAtComponents && !b.mediaAtComponents.find(({ name })=>name === 'min-width' || name === 'max-width')) {
|
|
35
|
-
return aAtToke.localeCompare(bAtToken);
|
|
36
|
-
}
|
|
37
|
-
if (aHasVendorSuffix && !bHasVendorSuffix) {
|
|
38
|
-
return 1;
|
|
39
|
-
} else if (!aHasVendorSuffix && bHasVendorSuffix) {
|
|
40
|
-
return -1;
|
|
41
|
-
}
|
|
42
|
-
if (aAtToke && !bAtToken) {
|
|
43
|
-
return 1;
|
|
44
|
-
} else if (!aAtToke && bAtToken) {
|
|
45
|
-
return -1;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
// 如果 a 和 b 的 id 相同,則按照以下規則排序
|
|
49
|
-
if (a.id === b.id && a.stateToken === b.stateToken) {
|
|
50
|
-
return a.name.localeCompare(b.name);
|
|
51
|
-
}
|
|
52
|
-
// 再按照 rule.order 本身來升序排列
|
|
53
|
-
return a.order - b.order;
|
|
54
|
-
}
|
|
55
|
-
}).map((eachRule)=>eachRule.name);
|
|
56
|
-
css.remove(...classes);
|
|
57
|
-
return orderedClasses;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export { reorderForReadableClasses as default };
|