@master/css 2.0.0-rc.68 → 2.0.0-rc.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common.cjs +0 -2
- package/dist/common.d.ts +0 -1
- package/dist/common.mjs +1 -2
- package/dist/config/functions.cjs +9 -243
- package/dist/config/functions.d.ts +137 -2
- package/dist/config/functions.mjs +9 -243
- package/dist/config/index.cjs +2 -2
- package/dist/config/index.mjs +2 -2
- package/dist/config/modes.cjs +307 -3
- package/dist/config/modes.d.ts +306 -2
- package/dist/config/modes.mjs +307 -3
- package/dist/config/rules.cjs +740 -782
- package/dist/config/rules.d.ts +692 -683
- package/dist/config/rules.mjs +741 -783
- package/dist/config/utilities.cjs +328 -97
- package/dist/config/utilities.d.ts +247 -16
- package/dist/config/utilities.mjs +328 -97
- package/dist/config/variables.cjs +88 -460
- package/dist/config/variables.d.ts +358 -369
- package/dist/config/variables.mjs +88 -460
- package/dist/core.cjs +234 -234
- package/dist/core.d.ts +5 -3
- package/dist/core.mjs +234 -234
- package/dist/create.cjs +10 -0
- package/dist/create.d.ts +3 -0
- package/dist/create.mjs +8 -0
- package/dist/declarers/core.group.cjs +99 -0
- package/dist/declarers/core.group.d.ts +2 -0
- package/dist/declarers/core.group.mjs +97 -0
- package/dist/declarers/core.variable.cjs +9 -0
- package/dist/declarers/core.variable.d.ts +4 -0
- package/dist/declarers/core.variable.mjs +7 -0
- package/dist/declarers/index.cjs +13 -0
- package/dist/declarers/index.d.ts +10 -0
- package/dist/declarers/index.mjs +11 -0
- package/dist/declarers/pair.cjs +12 -0
- package/dist/declarers/pair.d.ts +4 -0
- package/dist/declarers/pair.mjs +10 -0
- package/dist/factories/with-syntax-layer.cjs +0 -2
- package/dist/factories/with-syntax-layer.mjs +0 -2
- package/dist/function-transformers/core.calc.cjs +225 -0
- package/dist/function-transformers/core.calc.d.ts +2 -0
- package/dist/function-transformers/core.calc.mjs +223 -0
- package/dist/function-transformers/core.variable.cjs +23 -0
- package/dist/function-transformers/core.variable.d.ts +7 -0
- package/dist/function-transformers/core.variable.mjs +21 -0
- package/dist/function-transformers/index.cjs +11 -0
- package/dist/function-transformers/index.d.ts +8 -0
- package/dist/function-transformers/index.mjs +9 -0
- package/dist/index.cjs +10 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.mjs +6 -1
- package/dist/layer.cjs +2 -4
- package/dist/layer.mjs +2 -4
- package/dist/non-layer.cjs +2 -4
- package/dist/non-layer.mjs +2 -4
- package/dist/syntax-rule-type.cjs +8 -7
- package/dist/syntax-rule-type.d.ts +7 -7
- package/dist/syntax-rule-type.mjs +8 -7
- package/dist/syntax-rule.cjs +305 -258
- package/dist/syntax-rule.d.ts +2 -2
- package/dist/syntax-rule.mjs +306 -259
- package/dist/{utils/autofill-solid-style.cjs → transformers/auto-fill-solid.cjs} +3 -3
- package/dist/transformers/auto-fill-solid.d.ts +2 -0
- package/dist/{utils/autofill-solid-style.mjs → transformers/auto-fill-solid.mjs} +3 -3
- package/dist/transformers/index.cjs +9 -0
- package/dist/transformers/index.d.ts +6 -0
- package/dist/transformers/index.mjs +7 -0
- package/dist/types/common.d.ts +0 -2
- package/dist/types/config.d.ts +24 -20
- package/dist/types/syntax.d.ts +10 -8
- package/dist/utils/equal-selectors.cjs +1 -2
- package/dist/utils/equal-selectors.mjs +1 -2
- package/dist/utils/extend-config.cjs +83 -44
- package/dist/utils/extend-config.d.ts +10 -1
- package/dist/utils/extend-config.mjs +83 -44
- package/dist/utils/flatten-meta-object.cjs +38 -0
- package/dist/utils/flatten-meta-object.d.ts +13 -0
- package/dist/utils/flatten-meta-object.mjs +36 -0
- package/dist/utils/flatten-object.cjs +13 -9
- package/dist/utils/flatten-object.d.ts +1 -1
- package/dist/utils/flatten-object.mjs +13 -9
- package/dist/utils/generate-css.cjs +2 -2
- package/dist/utils/generate-css.d.ts +1 -2
- package/dist/utils/generate-css.mjs +2 -2
- package/dist/utils/minify-extended-config.cjs +64 -0
- package/dist/utils/minify-extended-config.d.ts +9 -0
- package/dist/utils/minify-extended-config.mjs +62 -0
- package/dist/utils/nest-meta-object.cjs +25 -0
- package/dist/utils/nest-meta-object.d.ts +7 -0
- package/dist/utils/nest-meta-object.mjs +23 -0
- package/dist/utils/parse-at.cjs +1 -2
- package/dist/utils/parse-at.d.ts +2 -2
- package/dist/utils/parse-at.mjs +1 -2
- package/dist/utils/parse-pair.cjs +3 -6
- package/dist/utils/parse-pair.mjs +3 -6
- package/dist/utils/parse-selector.cjs +2 -4
- package/dist/utils/parse-selector.d.ts +2 -2
- package/dist/utils/parse-selector.mjs +2 -4
- package/dist/utils/sort-readable-classes.cjs +2 -2
- package/dist/utils/sort-readable-classes.d.ts +1 -2
- package/dist/utils/sort-readable-classes.mjs +2 -2
- package/dist/variable-rule.cjs +35 -29
- package/dist/variable-rule.d.ts +16 -6
- package/dist/variable-rule.mjs +35 -29
- package/package.json +1 -1
- package/dist/utils/autofill-solid-style.d.ts +0 -3
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Minifies an extended config by hoisting shared variables from all modes into `variables`.
|
|
5
|
+
* Only variables with identical values across all modes are hoisted.
|
|
6
|
+
*
|
|
7
|
+
* @param config - The extended config with flattened variable structures
|
|
8
|
+
* @returns A new config with deduplicated `variables` and minimized `modes`
|
|
9
|
+
*/ function minifyExtendedConfig(config) {
|
|
10
|
+
const { variables: baseVariables = {}, modes = {}, ...rest } = config;
|
|
11
|
+
const modeNames = Object.keys(modes);
|
|
12
|
+
const variableNames = new Set();
|
|
13
|
+
// Collect all variable keys from all modes
|
|
14
|
+
for (const mode of modeNames){
|
|
15
|
+
for(const key in modes[mode]){
|
|
16
|
+
variableNames.add(key);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const variables = {
|
|
20
|
+
...baseVariables
|
|
21
|
+
};
|
|
22
|
+
const newModes = {};
|
|
23
|
+
for (const key of variableNames){
|
|
24
|
+
let first;
|
|
25
|
+
let allSame = true;
|
|
26
|
+
for(let i = 0; i < modeNames.length; i++){
|
|
27
|
+
const mode = modeNames[i];
|
|
28
|
+
const current = modes[mode]?.[key];
|
|
29
|
+
if (!current) {
|
|
30
|
+
allSame = false;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
if (i === 0) {
|
|
34
|
+
first = current;
|
|
35
|
+
} else if (JSON.stringify(current.value) !== JSON.stringify(first.value)) {
|
|
36
|
+
allSame = false;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const already = baseVariables[key];
|
|
41
|
+
const valueMatches = already && JSON.stringify(already.value) === JSON.stringify(first?.value);
|
|
42
|
+
if (allSame && (!already || valueMatches)) {
|
|
43
|
+
if (first) {
|
|
44
|
+
variables[key] = first;
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
for (const mode of modeNames){
|
|
48
|
+
if (!newModes[mode]) newModes[mode] = {};
|
|
49
|
+
const value = modes[mode]?.[key];
|
|
50
|
+
if (value) {
|
|
51
|
+
newModes[mode][key] = value;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const newConfig = {
|
|
57
|
+
...rest,
|
|
58
|
+
variables: Object.keys(variables).length > 0 ? variables : undefined,
|
|
59
|
+
modes: Object.keys(newModes).length > 0 ? newModes : undefined
|
|
60
|
+
};
|
|
61
|
+
return newConfig;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = minifyExtendedConfig;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ExtendedConfig } from './extend-config';
|
|
2
|
+
/**
|
|
3
|
+
* Minifies an extended config by hoisting shared variables from all modes into `variables`.
|
|
4
|
+
* Only variables with identical values across all modes are hoisted.
|
|
5
|
+
*
|
|
6
|
+
* @param config - The extended config with flattened variable structures
|
|
7
|
+
* @returns A new config with deduplicated `variables` and minimized `modes`
|
|
8
|
+
*/
|
|
9
|
+
export default function minifyExtendedConfig(config: ExtendedConfig): ExtendedConfig;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minifies an extended config by hoisting shared variables from all modes into `variables`.
|
|
3
|
+
* Only variables with identical values across all modes are hoisted.
|
|
4
|
+
*
|
|
5
|
+
* @param config - The extended config with flattened variable structures
|
|
6
|
+
* @returns A new config with deduplicated `variables` and minimized `modes`
|
|
7
|
+
*/ function minifyExtendedConfig(config) {
|
|
8
|
+
const { variables: baseVariables = {}, modes = {}, ...rest } = config;
|
|
9
|
+
const modeNames = Object.keys(modes);
|
|
10
|
+
const variableNames = new Set();
|
|
11
|
+
// Collect all variable keys from all modes
|
|
12
|
+
for (const mode of modeNames){
|
|
13
|
+
for(const key in modes[mode]){
|
|
14
|
+
variableNames.add(key);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const variables = {
|
|
18
|
+
...baseVariables
|
|
19
|
+
};
|
|
20
|
+
const newModes = {};
|
|
21
|
+
for (const key of variableNames){
|
|
22
|
+
let first;
|
|
23
|
+
let allSame = true;
|
|
24
|
+
for(let i = 0; i < modeNames.length; i++){
|
|
25
|
+
const mode = modeNames[i];
|
|
26
|
+
const current = modes[mode]?.[key];
|
|
27
|
+
if (!current) {
|
|
28
|
+
allSame = false;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
if (i === 0) {
|
|
32
|
+
first = current;
|
|
33
|
+
} else if (JSON.stringify(current.value) !== JSON.stringify(first.value)) {
|
|
34
|
+
allSame = false;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const already = baseVariables[key];
|
|
39
|
+
const valueMatches = already && JSON.stringify(already.value) === JSON.stringify(first?.value);
|
|
40
|
+
if (allSame && (!already || valueMatches)) {
|
|
41
|
+
if (first) {
|
|
42
|
+
variables[key] = first;
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
for (const mode of modeNames){
|
|
46
|
+
if (!newModes[mode]) newModes[mode] = {};
|
|
47
|
+
const value = modes[mode]?.[key];
|
|
48
|
+
if (value) {
|
|
49
|
+
newModes[mode][key] = value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const newConfig = {
|
|
55
|
+
...rest,
|
|
56
|
+
variables: Object.keys(variables).length > 0 ? variables : undefined,
|
|
57
|
+
modes: Object.keys(newModes).length > 0 ? newModes : undefined
|
|
58
|
+
};
|
|
59
|
+
return newConfig;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { minifyExtendedConfig as default };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function nestMetaObject(flat) {
|
|
4
|
+
const nested = {};
|
|
5
|
+
for (const entry of Object.values(flat)){
|
|
6
|
+
const { group, key, value } = entry;
|
|
7
|
+
const path = group ? group.split('.') : [];
|
|
8
|
+
let current = nested;
|
|
9
|
+
for (const segment of path){
|
|
10
|
+
if (!(segment in current)) {
|
|
11
|
+
current[segment] = {};
|
|
12
|
+
} else if (typeof current[segment] !== 'object' || current[segment] === null) {
|
|
13
|
+
// Wrap primitive into object: { '': value }
|
|
14
|
+
current[segment] = {
|
|
15
|
+
'': current[segment]
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
current = current[segment];
|
|
19
|
+
}
|
|
20
|
+
current[key] = value;
|
|
21
|
+
}
|
|
22
|
+
return nested;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = nestMetaObject;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
function nestMetaObject(flat) {
|
|
2
|
+
const nested = {};
|
|
3
|
+
for (const entry of Object.values(flat)){
|
|
4
|
+
const { group, key, value } = entry;
|
|
5
|
+
const path = group ? group.split('.') : [];
|
|
6
|
+
let current = nested;
|
|
7
|
+
for (const segment of path){
|
|
8
|
+
if (!(segment in current)) {
|
|
9
|
+
current[segment] = {};
|
|
10
|
+
} else if (typeof current[segment] !== 'object' || current[segment] === null) {
|
|
11
|
+
// Wrap primitive into object: { '': value }
|
|
12
|
+
current[segment] = {
|
|
13
|
+
'': current[segment]
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
current = current[segment];
|
|
17
|
+
}
|
|
18
|
+
current[key] = value;
|
|
19
|
+
}
|
|
20
|
+
return nested;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { nestMetaObject as default };
|
package/dist/utils/parse-at.cjs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var common = require('../common.cjs');
|
|
4
|
-
var core = require('../core.cjs');
|
|
5
4
|
var parsePair = require('./parse-pair.cjs');
|
|
6
5
|
var parseValue = require('./parse-value.cjs');
|
|
7
6
|
var replaceCharOutsideQuotes = require('./replace-char-outside-quotes.cjs');
|
|
8
7
|
var splitCharOutsideQuotes = require('./split-char-outside-quotes.cjs');
|
|
9
8
|
|
|
10
|
-
function parseAt(token, css
|
|
9
|
+
function parseAt(token, css, isRaw = true) {
|
|
11
10
|
let id;
|
|
12
11
|
let firstToken;
|
|
13
12
|
const resolve = (token)=>{
|
package/dist/utils/parse-at.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import MasterCSS from '../core';
|
|
1
|
+
import type MasterCSS from '../core';
|
|
2
2
|
import { AtIdentifier } from '../types/config';
|
|
3
3
|
export type AtRule = {
|
|
4
4
|
id: AtIdentifier;
|
|
@@ -36,4 +36,4 @@ export interface AtRuleGroupNode {
|
|
|
36
36
|
children: AtRuleNode[];
|
|
37
37
|
}
|
|
38
38
|
export type AtRuleNode = AtRuleValueNode | AtRuleComparisonOperatorNode | AtRuleLogicalOperatorNode | AtRuleGroupNode;
|
|
39
|
-
export default function parseAt(token: string, css
|
|
39
|
+
export default function parseAt(token: string, css: MasterCSS, isRaw?: boolean): AtRule;
|
package/dist/utils/parse-at.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { AT_COMPARISON_OPERATORS, AT_LOGICAL_OPERATORS, AT_IDENTIFIERS, AT_COMPARABLE_FEATURES } from '../common.mjs';
|
|
2
|
-
import MasterCSS from '../core.mjs';
|
|
3
2
|
import parsePair from './parse-pair.mjs';
|
|
4
3
|
import parseValue from './parse-value.mjs';
|
|
5
4
|
import replaceCharOutsideQuotes from './replace-char-outside-quotes.mjs';
|
|
6
5
|
import splitCharOutsideQuotes from './split-char-outside-quotes.mjs';
|
|
7
6
|
|
|
8
|
-
function parseAt(token, css
|
|
7
|
+
function parseAt(token, css, isRaw = true) {
|
|
9
8
|
let id;
|
|
10
9
|
let firstToken;
|
|
11
10
|
const resolve = (token)=>{
|
|
@@ -9,18 +9,15 @@ function parsePair(str, a = '(', b = ')') {
|
|
|
9
9
|
const prevChar = str[i - 1];
|
|
10
10
|
// 處理 escape 字元,例如 \"
|
|
11
11
|
if (char === '\\') {
|
|
12
|
-
i
|
|
13
|
-
;
|
|
12
|
+
i++; // skip next character
|
|
14
13
|
continue;
|
|
15
14
|
}
|
|
16
15
|
// 處理字串區段進入與離開
|
|
17
16
|
if ((char === '"' || char === '\'') && prevChar !== '\\') {
|
|
18
17
|
if (inString === char) {
|
|
19
|
-
inString = null // 離開字串
|
|
20
|
-
;
|
|
18
|
+
inString = null; // 離開字串
|
|
21
19
|
} else if (!inString) {
|
|
22
|
-
inString = char // 進入字串
|
|
23
|
-
;
|
|
20
|
+
inString = char; // 進入字串
|
|
24
21
|
}
|
|
25
22
|
continue;
|
|
26
23
|
}
|
|
@@ -7,18 +7,15 @@ function parsePair(str, a = '(', b = ')') {
|
|
|
7
7
|
const prevChar = str[i - 1];
|
|
8
8
|
// 處理 escape 字元,例如 \"
|
|
9
9
|
if (char === '\\') {
|
|
10
|
-
i
|
|
11
|
-
;
|
|
10
|
+
i++; // skip next character
|
|
12
11
|
continue;
|
|
13
12
|
}
|
|
14
13
|
// 處理字串區段進入與離開
|
|
15
14
|
if ((char === '"' || char === '\'') && prevChar !== '\\') {
|
|
16
15
|
if (inString === char) {
|
|
17
|
-
inString = null // 離開字串
|
|
18
|
-
;
|
|
16
|
+
inString = null; // 離開字串
|
|
19
17
|
} else if (!inString) {
|
|
20
|
-
inString = char // 進入字串
|
|
21
|
-
;
|
|
18
|
+
inString = char; // 進入字串
|
|
22
19
|
}
|
|
23
20
|
continue;
|
|
24
21
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var common = require('../common.cjs');
|
|
4
|
-
var core = require('../core.cjs');
|
|
5
4
|
var parsePair = require('./parse-pair.cjs');
|
|
6
5
|
|
|
7
6
|
const SELECTOR_REGEX = new RegExp(`(?:[a-zA-Z0-9-]+)|([${common.SELECTOR_COMBINATORS.join('')}#.:,*])|(a-zA-Z0-9-)`, 'g');
|
|
8
|
-
function parseSelector(token, css
|
|
7
|
+
function parseSelector(token, css, isRaw = true) {
|
|
9
8
|
const resolve = (eachToken)=>{
|
|
10
9
|
const nodes = [];
|
|
11
10
|
let currentPrefix = '';
|
|
@@ -38,8 +37,7 @@ function parseSelector(token, css = new core(), isRaw = true) {
|
|
|
38
37
|
const nextRawValue = eachToken[tokenIndex];
|
|
39
38
|
const prevRawValue = eachToken[tokenIndex - raw.length - 1];
|
|
40
39
|
if (prevRawValue !== '_' && nextRawValue !== '_') {
|
|
41
|
-
value = ' ' // support BEM __
|
|
42
|
-
;
|
|
40
|
+
value = ' '; // support BEM __
|
|
43
41
|
}
|
|
44
42
|
}
|
|
45
43
|
} else if (raw === ',') {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import MasterCSS from '../core';
|
|
1
|
+
import type MasterCSS from '../core';
|
|
2
2
|
export declare type SelectorLiteralNode = {
|
|
3
3
|
type?: 'attribute' | 'pseudo-class' | 'pseudo-element' | 'class' | 'universal' | 'id';
|
|
4
4
|
raw?: string;
|
|
@@ -16,4 +16,4 @@ export declare type SelectorCombinatorNode = {
|
|
|
16
16
|
value: string;
|
|
17
17
|
};
|
|
18
18
|
export declare type SelectorNode = SelectorLiteralNode | SelectorCombinatorNode | SelectorSeparatorNode;
|
|
19
|
-
export default function parseSelector(token: string, css
|
|
19
|
+
export default function parseSelector(token: string, css: MasterCSS, isRaw?: boolean): SelectorNode[];
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { SELECTOR_COMBINATORS } from '../common.mjs';
|
|
2
|
-
import MasterCSS from '../core.mjs';
|
|
3
2
|
import parsePair from './parse-pair.mjs';
|
|
4
3
|
|
|
5
4
|
const SELECTOR_REGEX = new RegExp(`(?:[a-zA-Z0-9-]+)|([${SELECTOR_COMBINATORS.join('')}#.:,*])|(a-zA-Z0-9-)`, 'g');
|
|
6
|
-
function parseSelector(token, css
|
|
5
|
+
function parseSelector(token, css, isRaw = true) {
|
|
7
6
|
const resolve = (eachToken)=>{
|
|
8
7
|
const nodes = [];
|
|
9
8
|
let currentPrefix = '';
|
|
@@ -36,8 +35,7 @@ function parseSelector(token, css = new MasterCSS(), isRaw = true) {
|
|
|
36
35
|
const nextRawValue = eachToken[tokenIndex];
|
|
37
36
|
const prevRawValue = eachToken[tokenIndex - raw.length - 1];
|
|
38
37
|
if (prevRawValue !== '_' && nextRawValue !== '_') {
|
|
39
|
-
value = ' ' // support BEM __
|
|
40
|
-
;
|
|
38
|
+
value = ' '; // support BEM __
|
|
41
39
|
}
|
|
42
40
|
}
|
|
43
41
|
} else if (raw === ',') {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var syntaxRuleType = require('../syntax-rule-type.cjs');
|
|
4
|
-
var
|
|
4
|
+
var create = require('../create.cjs');
|
|
5
5
|
var compareRulePriority = require('./compare-rule-priority.cjs');
|
|
6
6
|
var common = require('../common.cjs');
|
|
7
7
|
|
|
@@ -10,7 +10,7 @@ var common = require('../common.cjs');
|
|
|
10
10
|
* @param classes
|
|
11
11
|
* @param options
|
|
12
12
|
* @returns consistent classes
|
|
13
|
-
*/ function sortReadableClasses(classes, css =
|
|
13
|
+
*/ function sortReadableClasses(classes, css = create()) {
|
|
14
14
|
const shouldSortClasses = [];
|
|
15
15
|
const unsortedClasses = [];
|
|
16
16
|
for (const className of classes){
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import MasterCSS from '../core';
|
|
2
1
|
/**
|
|
3
2
|
* Sorts classes in a consistent order
|
|
4
3
|
* @param classes
|
|
5
4
|
* @param options
|
|
6
5
|
* @returns consistent classes
|
|
7
6
|
*/
|
|
8
|
-
export default function sortReadableClasses(classes: string[], css?: MasterCSS): string[];
|
|
7
|
+
export default function sortReadableClasses(classes: string[], css?: import("..").MasterCSS): string[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import SyntaxRuleType from '../syntax-rule-type.mjs';
|
|
2
|
-
import
|
|
2
|
+
import createCSS from '../create.mjs';
|
|
3
3
|
import compareRulePriority from './compare-rule-priority.mjs';
|
|
4
4
|
import { __UNSORTED__ } from '../common.mjs';
|
|
5
5
|
|
|
@@ -8,7 +8,7 @@ import { __UNSORTED__ } from '../common.mjs';
|
|
|
8
8
|
* @param classes
|
|
9
9
|
* @param options
|
|
10
10
|
* @returns consistent classes
|
|
11
|
-
*/ function sortReadableClasses(classes, css =
|
|
11
|
+
*/ function sortReadableClasses(classes, css = createCSS()) {
|
|
12
12
|
const shouldSortClasses = [];
|
|
13
13
|
const unsortedClasses = [];
|
|
14
14
|
for (const className of classes){
|
package/dist/variable-rule.cjs
CHANGED
|
@@ -6,28 +6,25 @@ class VariableRule {
|
|
|
6
6
|
name;
|
|
7
7
|
variable;
|
|
8
8
|
css;
|
|
9
|
-
nodes;
|
|
9
|
+
nodes = [];
|
|
10
10
|
constructor(name, variable, css){
|
|
11
11
|
this.name = name;
|
|
12
12
|
this.variable = variable;
|
|
13
13
|
this.css = css;
|
|
14
|
-
this.nodes = [];
|
|
15
14
|
const hasDefaultValue = variable.value !== undefined;
|
|
16
15
|
if (hasDefaultValue) {
|
|
17
|
-
this.nodes.push(new VariableRuleNode(this
|
|
16
|
+
this.nodes.push(new VariableRuleNode(this, variable, css));
|
|
18
17
|
}
|
|
19
|
-
if (variable.modes) {
|
|
18
|
+
if (variable.modes && this.css.config.modeTrigger) {
|
|
20
19
|
for(const mode in variable.modes){
|
|
21
20
|
const modeVariable = variable.modes[mode];
|
|
22
|
-
const variableRule = new VariableRuleNode(this
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.nodes.push(variableRule);
|
|
30
|
-
}
|
|
21
|
+
const variableRule = new VariableRuleNode(this, modeVariable, css, mode);
|
|
22
|
+
const isDefaultMode = hasDefaultValue ? false : this.css.config.defaultMode === mode;
|
|
23
|
+
variableRule.isDefaultMode = isDefaultMode;
|
|
24
|
+
if (isDefaultMode) {
|
|
25
|
+
this.nodes.unshift(variableRule);
|
|
26
|
+
} else {
|
|
27
|
+
this.nodes.push(variableRule);
|
|
31
28
|
}
|
|
32
29
|
}
|
|
33
30
|
}
|
|
@@ -40,42 +37,51 @@ class VariableRule {
|
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
39
|
class VariableRuleNode {
|
|
43
|
-
|
|
40
|
+
rule;
|
|
44
41
|
variable;
|
|
45
42
|
css;
|
|
46
43
|
mode;
|
|
47
44
|
native;
|
|
48
|
-
isDefaultMode;
|
|
49
|
-
constructor(
|
|
50
|
-
this.
|
|
45
|
+
isDefaultMode = false;
|
|
46
|
+
constructor(rule, variable, css, mode){
|
|
47
|
+
this.rule = rule;
|
|
51
48
|
this.variable = variable;
|
|
52
49
|
this.css = css;
|
|
53
50
|
this.mode = mode;
|
|
54
|
-
this.isDefaultMode = false;
|
|
55
|
-
}
|
|
56
|
-
get modeTrigger() {
|
|
57
|
-
return this.mode ? this.css.config.modes?.[this.mode] : undefined;
|
|
58
51
|
}
|
|
59
52
|
get selectorText() {
|
|
60
53
|
const isDefaultMode = this.isDefaultMode;
|
|
61
54
|
if (this.mode) {
|
|
62
|
-
switch(this.modeTrigger){
|
|
63
|
-
case 'media':
|
|
64
|
-
return ':root';
|
|
55
|
+
switch(this.css.config.modeTrigger){
|
|
65
56
|
case 'host':
|
|
66
|
-
return `:host(.${this.mode})
|
|
57
|
+
return `:host(.${this.mode})${isDefaultMode ? ',:host' : ''}`;
|
|
67
58
|
case 'class':
|
|
68
|
-
return `.${this.mode}
|
|
59
|
+
return `.${this.mode}${isDefaultMode ? ',:root' : ''}`;
|
|
69
60
|
default:
|
|
70
|
-
return '';
|
|
61
|
+
return ':root';
|
|
71
62
|
}
|
|
72
63
|
} else {
|
|
73
64
|
return ':root';
|
|
74
65
|
}
|
|
75
66
|
}
|
|
76
67
|
get text() {
|
|
77
|
-
let
|
|
78
|
-
|
|
68
|
+
let value = '';
|
|
69
|
+
switch(this.rule.variable.type){
|
|
70
|
+
case 'color':
|
|
71
|
+
{
|
|
72
|
+
const color = this.variable;
|
|
73
|
+
value = (color.alpha ?? 1) < 1 ? `${color.space}(${color.value}/${color.alpha})` : `${color.space}(${color.value})`;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
case 'number':
|
|
77
|
+
value = String(this.variable.value);
|
|
78
|
+
break;
|
|
79
|
+
case 'string':
|
|
80
|
+
value = this.variable.value;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
let text = `${this.selectorText}{--${this.rule.name}:${value}}`;
|
|
84
|
+
if (this.css.config.modeTrigger === 'media' && this.mode) {
|
|
79
85
|
text = `@media (prefers-color-scheme:${this.mode}){${text}}`;
|
|
80
86
|
}
|
|
81
87
|
return text;
|
package/dist/variable-rule.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import MasterCSS from './core';
|
|
2
|
-
import { LiteralVariable, Variable } from './types/syntax';
|
|
2
|
+
import { ColorVariable, LiteralVariable, NumberVariable, StringVariable, Variable } from './types/syntax';
|
|
3
3
|
export default class VariableRule {
|
|
4
4
|
readonly name: string;
|
|
5
5
|
readonly variable: Variable;
|
|
@@ -9,15 +9,25 @@ export default class VariableRule {
|
|
|
9
9
|
get key(): string;
|
|
10
10
|
get text(): string;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
type VariableMap = {
|
|
13
|
+
string: StringVariable;
|
|
14
|
+
number: NumberVariable;
|
|
15
|
+
color: ColorVariable;
|
|
16
|
+
};
|
|
17
|
+
type VariableType = LiteralVariable['type'];
|
|
18
|
+
export declare class VariableRuleNode<T extends VariableType = VariableType> {
|
|
19
|
+
readonly rule: VariableRule & {
|
|
20
|
+
variable: VariableMap[T];
|
|
21
|
+
};
|
|
22
|
+
readonly variable: VariableMap[T];
|
|
15
23
|
readonly css: MasterCSS;
|
|
16
24
|
readonly mode?: string | undefined;
|
|
17
25
|
native?: CSSRule;
|
|
18
26
|
isDefaultMode: boolean;
|
|
19
|
-
constructor(
|
|
20
|
-
|
|
27
|
+
constructor(rule: VariableRule & {
|
|
28
|
+
variable: VariableMap[T];
|
|
29
|
+
}, variable: VariableMap[T], css: MasterCSS, mode?: string | undefined);
|
|
21
30
|
get selectorText(): string;
|
|
22
31
|
get text(): string;
|
|
23
32
|
}
|
|
33
|
+
export {};
|
package/dist/variable-rule.mjs
CHANGED
|
@@ -2,28 +2,25 @@ class VariableRule {
|
|
|
2
2
|
name;
|
|
3
3
|
variable;
|
|
4
4
|
css;
|
|
5
|
-
nodes;
|
|
5
|
+
nodes = [];
|
|
6
6
|
constructor(name, variable, css){
|
|
7
7
|
this.name = name;
|
|
8
8
|
this.variable = variable;
|
|
9
9
|
this.css = css;
|
|
10
|
-
this.nodes = [];
|
|
11
10
|
const hasDefaultValue = variable.value !== undefined;
|
|
12
11
|
if (hasDefaultValue) {
|
|
13
|
-
this.nodes.push(new VariableRuleNode(this
|
|
12
|
+
this.nodes.push(new VariableRuleNode(this, variable, css));
|
|
14
13
|
}
|
|
15
|
-
if (variable.modes) {
|
|
14
|
+
if (variable.modes && this.css.config.modeTrigger) {
|
|
16
15
|
for(const mode in variable.modes){
|
|
17
16
|
const modeVariable = variable.modes[mode];
|
|
18
|
-
const variableRule = new VariableRuleNode(this
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
this.nodes.push(variableRule);
|
|
26
|
-
}
|
|
17
|
+
const variableRule = new VariableRuleNode(this, modeVariable, css, mode);
|
|
18
|
+
const isDefaultMode = hasDefaultValue ? false : this.css.config.defaultMode === mode;
|
|
19
|
+
variableRule.isDefaultMode = isDefaultMode;
|
|
20
|
+
if (isDefaultMode) {
|
|
21
|
+
this.nodes.unshift(variableRule);
|
|
22
|
+
} else {
|
|
23
|
+
this.nodes.push(variableRule);
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
26
|
}
|
|
@@ -36,42 +33,51 @@ class VariableRule {
|
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
35
|
class VariableRuleNode {
|
|
39
|
-
|
|
36
|
+
rule;
|
|
40
37
|
variable;
|
|
41
38
|
css;
|
|
42
39
|
mode;
|
|
43
40
|
native;
|
|
44
|
-
isDefaultMode;
|
|
45
|
-
constructor(
|
|
46
|
-
this.
|
|
41
|
+
isDefaultMode = false;
|
|
42
|
+
constructor(rule, variable, css, mode){
|
|
43
|
+
this.rule = rule;
|
|
47
44
|
this.variable = variable;
|
|
48
45
|
this.css = css;
|
|
49
46
|
this.mode = mode;
|
|
50
|
-
this.isDefaultMode = false;
|
|
51
|
-
}
|
|
52
|
-
get modeTrigger() {
|
|
53
|
-
return this.mode ? this.css.config.modes?.[this.mode] : undefined;
|
|
54
47
|
}
|
|
55
48
|
get selectorText() {
|
|
56
49
|
const isDefaultMode = this.isDefaultMode;
|
|
57
50
|
if (this.mode) {
|
|
58
|
-
switch(this.modeTrigger){
|
|
59
|
-
case 'media':
|
|
60
|
-
return ':root';
|
|
51
|
+
switch(this.css.config.modeTrigger){
|
|
61
52
|
case 'host':
|
|
62
|
-
return `:host(.${this.mode})
|
|
53
|
+
return `:host(.${this.mode})${isDefaultMode ? ',:host' : ''}`;
|
|
63
54
|
case 'class':
|
|
64
|
-
return `.${this.mode}
|
|
55
|
+
return `.${this.mode}${isDefaultMode ? ',:root' : ''}`;
|
|
65
56
|
default:
|
|
66
|
-
return '';
|
|
57
|
+
return ':root';
|
|
67
58
|
}
|
|
68
59
|
} else {
|
|
69
60
|
return ':root';
|
|
70
61
|
}
|
|
71
62
|
}
|
|
72
63
|
get text() {
|
|
73
|
-
let
|
|
74
|
-
|
|
64
|
+
let value = '';
|
|
65
|
+
switch(this.rule.variable.type){
|
|
66
|
+
case 'color':
|
|
67
|
+
{
|
|
68
|
+
const color = this.variable;
|
|
69
|
+
value = (color.alpha ?? 1) < 1 ? `${color.space}(${color.value}/${color.alpha})` : `${color.space}(${color.value})`;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case 'number':
|
|
73
|
+
value = String(this.variable.value);
|
|
74
|
+
break;
|
|
75
|
+
case 'string':
|
|
76
|
+
value = this.variable.value;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
let text = `${this.selectorText}{--${this.rule.name}:${value}}`;
|
|
80
|
+
if (this.css.config.modeTrigger === 'media' && this.mode) {
|
|
75
81
|
text = `@media (prefers-color-scheme:${this.mode}){${text}}`;
|
|
76
82
|
}
|
|
77
83
|
return text;
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@master/css","type":"module","scripts":{"build":"techor build \"src/**/*.ts\"","dev":"pnpm build --watch","test":"vitest","type-check":"tsc --noEmit","lint":"eslint"},"license":"MIT","description":"The CSS language and framework for rapidly building modern and high-performance websites","author":"Aoyue Design LLC.","funding":"https://rc.css.master.co/sponsor","homepage":"https://css.master.co","bugs":{"url":"https://github.com/master-co/css/issues"},"repository":{"type":"git","url":"https://github.com/master-co/css.git","directory":"packages/core"},"keywords":["style","styles","html","variants","virtual","virtual-css","utility","css","ui","lightweight","class","webpack","plugin","integration","vite","parcel","build-tools","mastercss"],"sideEffects":false,"main":"./dist/index.cjs","jsnext:main":"./dist/index.mjs","esnext":"./dist/index.mjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","require":"./dist/index.cjs","import":"./dist/index.mjs"}},"bin":"./dist/bin/index.mjs","files":["dist"],"publishConfig":{"access":"public","provenance":true},"dependencies":{"@master/colors":"^
|
|
1
|
+
{"name":"@master/css","type":"module","scripts":{"build":"techor build \"src/**/*.ts\"","dev":"pnpm build --watch","test":"vitest","bench":"vitest bench","type-check":"tsc --noEmit","lint":"eslint"},"license":"MIT","description":"The CSS language and framework for rapidly building modern and high-performance websites","author":"Aoyue Design LLC.","funding":"https://rc.css.master.co/sponsor","homepage":"https://css.master.co","bugs":{"url":"https://github.com/master-co/css/issues"},"repository":{"type":"git","url":"https://github.com/master-co/css.git","directory":"packages/core"},"keywords":["style","styles","html","variants","virtual","virtual-css","utility","css","ui","lightweight","class","webpack","plugin","integration","vite","parcel","build-tools","mastercss"],"sideEffects":false,"main":"./dist/index.cjs","jsnext:main":"./dist/index.mjs","esnext":"./dist/index.mjs","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","require":"./dist/index.cjs","import":"./dist/index.mjs"},"./*":{"types":"./dist/*.d.ts","require":"./dist/*.cjs","import":"./dist/*.mjs"}},"bin":"./dist/bin/index.mjs","files":["dist"],"publishConfig":{"access":"public","provenance":true},"dependencies":{"@master/colors":"^3.0.0","@master/normal.css":"^3.2.0","csstype":"^3.1.3","json-safe-extend":"^3.2.5"},"devDependencies":{"shared":"^2.0.0-rc.69"},"version":"2.0.0-rc.69"}
|