@master/css 2.0.0-rc.25 → 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.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
package/dist/config/index.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var queries = require('./queries.cjs');
|
|
3
4
|
var selectors = require('./selectors.cjs');
|
|
4
5
|
var semantics = require('./semantics.cjs');
|
|
5
6
|
var animations = require('./animations.cjs');
|
|
6
7
|
var variables = require('./variables.cjs');
|
|
7
8
|
var rules = require('./rules.cjs');
|
|
8
9
|
var functions = require('./functions.cjs');
|
|
9
|
-
var screenSizes = require('../tokens/screen-sizes.cjs');
|
|
10
10
|
|
|
11
11
|
const config = {
|
|
12
|
-
|
|
12
|
+
queries,
|
|
13
13
|
selectors,
|
|
14
14
|
semantics,
|
|
15
15
|
rules: rules.default,
|
|
@@ -21,14 +21,14 @@ const config = {
|
|
|
21
21
|
baseUnit: 4,
|
|
22
22
|
override: false,
|
|
23
23
|
important: false,
|
|
24
|
-
|
|
24
|
+
modeDriver: 'class'
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
+
exports.queries = queries;
|
|
27
28
|
exports.selectors = selectors;
|
|
28
29
|
exports.semantics = semantics;
|
|
29
30
|
exports.animations = animations;
|
|
30
31
|
exports.variables = variables;
|
|
31
32
|
exports.rules = rules.default;
|
|
32
33
|
exports.functions = functions;
|
|
33
|
-
exports.mediaQueries = screenSizes;
|
|
34
34
|
exports.config = config;
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import queries from './queries';
|
|
2
2
|
import selectors from './selectors';
|
|
3
3
|
import semantics from './semantics';
|
|
4
4
|
import animations from './animations';
|
|
@@ -8,7 +8,7 @@ import functions from './functions';
|
|
|
8
8
|
import type { PropertiesHyphen } from 'csstype';
|
|
9
9
|
import type { Rule, RuleDefinition, ValueComponent } from '../rule';
|
|
10
10
|
declare const config: Config;
|
|
11
|
-
export { config,
|
|
11
|
+
export { config, queries, selectors, semantics, rules, functions, animations, variables };
|
|
12
12
|
export type VariableValue = number | string | Array<number | string>;
|
|
13
13
|
export type VariableDefinition = {
|
|
14
14
|
[key in '' | `@${string}` | string]?: VariableValue | VariableDefinition;
|
|
@@ -52,7 +52,7 @@ export type FunctionDefinitions = {
|
|
|
52
52
|
export interface Config {
|
|
53
53
|
extends?: (Config | any)[];
|
|
54
54
|
styles?: StyleDefinitions;
|
|
55
|
-
|
|
55
|
+
queries?: MediaQueryDefinitions;
|
|
56
56
|
selectors?: SelectorDefinitions;
|
|
57
57
|
semantics?: SemanticDefinitions;
|
|
58
58
|
variables?: VariableDefinitions;
|
|
@@ -64,5 +64,5 @@ export interface Config {
|
|
|
64
64
|
override?: boolean;
|
|
65
65
|
functions?: FunctionDefinitions;
|
|
66
66
|
animations?: AnimationDefinitions;
|
|
67
|
-
|
|
67
|
+
modeDriver?: 'class' | 'media' | 'host';
|
|
68
68
|
}
|
package/dist/config/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import queries from './queries.mjs';
|
|
1
2
|
import selectors from './selectors.mjs';
|
|
2
3
|
import semantics from './semantics.mjs';
|
|
3
4
|
import animations from './animations.mjs';
|
|
4
5
|
import variables from './variables.mjs';
|
|
5
6
|
import rules from './rules.mjs';
|
|
6
7
|
import functions from './functions.mjs';
|
|
7
|
-
import mediaQueries from '../tokens/screen-sizes.mjs';
|
|
8
8
|
|
|
9
9
|
const config = {
|
|
10
|
-
|
|
10
|
+
queries,
|
|
11
11
|
selectors,
|
|
12
12
|
semantics,
|
|
13
13
|
rules,
|
|
@@ -19,7 +19,7 @@ const config = {
|
|
|
19
19
|
baseUnit: 4,
|
|
20
20
|
override: false,
|
|
21
21
|
important: false,
|
|
22
|
-
|
|
22
|
+
modeDriver: 'class'
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
export { animations, config, functions,
|
|
25
|
+
export { animations, config, functions, queries, rules, selectors, semantics, variables };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var screenSizes = require('../tokens/screen-sizes.cjs');
|
|
4
|
+
|
|
5
|
+
const queries = {
|
|
6
|
+
landscape: 'media (orientation:landscape)',
|
|
7
|
+
portrait: 'media (orientation:portrait)',
|
|
8
|
+
motion: 'media (prefers-reduced-motion:no-preference)',
|
|
9
|
+
'reduced-motion': 'media (prefers-reduced-motion:reduce)',
|
|
10
|
+
...screenSizes
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
module.exports = queries;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare const queries: {
|
|
2
|
+
'4xs': number;
|
|
3
|
+
'3xs': number;
|
|
4
|
+
'2xs': number;
|
|
5
|
+
xs: number;
|
|
6
|
+
sm: number;
|
|
7
|
+
md: number;
|
|
8
|
+
lg: number;
|
|
9
|
+
xl: number;
|
|
10
|
+
'2xl': number;
|
|
11
|
+
'3xl': number;
|
|
12
|
+
'4xl': number;
|
|
13
|
+
landscape: string;
|
|
14
|
+
portrait: string;
|
|
15
|
+
motion: string;
|
|
16
|
+
'reduced-motion': string;
|
|
17
|
+
};
|
|
18
|
+
export default queries;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import screenSizes from '../tokens/screen-sizes.mjs';
|
|
2
|
+
|
|
3
|
+
const queries = {
|
|
4
|
+
landscape: 'media (orientation:landscape)',
|
|
5
|
+
portrait: 'media (orientation:portrait)',
|
|
6
|
+
motion: 'media (prefers-reduced-motion:no-preference)',
|
|
7
|
+
'reduced-motion': 'media (prefers-reduced-motion:reduce)',
|
|
8
|
+
...screenSizes
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { queries as default };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import colors from '@master/colors';
|
|
2
|
-
import
|
|
2
|
+
import screenSizes from '../tokens/screen-sizes.mjs';
|
|
3
3
|
|
|
4
4
|
const variables = {
|
|
5
5
|
full: '100%',
|
|
@@ -42,7 +42,7 @@ const variables = {
|
|
|
42
42
|
'serif'
|
|
43
43
|
]
|
|
44
44
|
},
|
|
45
|
-
screen:
|
|
45
|
+
screen: screenSizes,
|
|
46
46
|
'font-weight': {
|
|
47
47
|
thin: 100,
|
|
48
48
|
extralight: 200,
|
package/dist/core.cjs
CHANGED
|
@@ -7,7 +7,7 @@ var index = require('./config/index.cjs');
|
|
|
7
7
|
var layer = require('./layer.cjs');
|
|
8
8
|
var hexToRgb = require('./utils/hex-to-rgb.cjs');
|
|
9
9
|
var flattenObject = require('./utils/flatten-object.cjs');
|
|
10
|
-
var extendConfig = require('./
|
|
10
|
+
var extendConfig = require('./functions/extend-config.cjs');
|
|
11
11
|
|
|
12
12
|
class MasterCSS {
|
|
13
13
|
customConfig;
|
|
@@ -26,9 +26,9 @@ class MasterCSS {
|
|
|
26
26
|
this.RegisteredSemanticRules = [];
|
|
27
27
|
this.RegisteredRules = [];
|
|
28
28
|
if (!customConfig?.override) {
|
|
29
|
-
this.config = extendConfig
|
|
29
|
+
this.config = extendConfig(index.config, customConfig);
|
|
30
30
|
} else {
|
|
31
|
-
this.config = extendConfig
|
|
31
|
+
this.config = extendConfig(customConfig);
|
|
32
32
|
}
|
|
33
33
|
this.resolve();
|
|
34
34
|
if (this.constructor === MasterCSS) {
|
|
@@ -40,7 +40,7 @@ class MasterCSS {
|
|
|
40
40
|
this.stylesBy = {};
|
|
41
41
|
this.selectors = {};
|
|
42
42
|
this.variables = {};
|
|
43
|
-
this.
|
|
43
|
+
this.queries = {};
|
|
44
44
|
this.animations = {};
|
|
45
45
|
this.RegisteredRules.length = 0;
|
|
46
46
|
this.RegisteredSemanticRules.length = 0;
|
|
@@ -51,7 +51,7 @@ class MasterCSS {
|
|
|
51
51
|
currentColor: undefined,
|
|
52
52
|
transparent: undefined
|
|
53
53
|
};
|
|
54
|
-
const { styles, selectors, variables, semantics,
|
|
54
|
+
const { styles, selectors, variables, semantics, queries, rules, animations } = this.config;
|
|
55
55
|
function escapeString(str) {
|
|
56
56
|
return str.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
57
57
|
}
|
|
@@ -82,9 +82,9 @@ class MasterCSS {
|
|
|
82
82
|
}
|
|
83
83
|
if (variables) {
|
|
84
84
|
const unexecutedAliasVariable = {};
|
|
85
|
-
const parseVariable = (variable, name,
|
|
85
|
+
const parseVariable = (variable, name, mode)=>{
|
|
86
86
|
if (!variable) return;
|
|
87
|
-
const addVariable = (name, variableValue,
|
|
87
|
+
const addVariable = (name, variableValue, replacedMode, alpha)=>{
|
|
88
88
|
if (variableValue === undefined) return;
|
|
89
89
|
if (variableValue.type === 'color') {
|
|
90
90
|
if (alpha) {
|
|
@@ -96,15 +96,15 @@ class MasterCSS {
|
|
|
96
96
|
}
|
|
97
97
|
colorVariableNames[name] = undefined;
|
|
98
98
|
}
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
99
|
+
const currentMode = replacedMode ?? mode;
|
|
100
|
+
if (currentMode !== undefined) {
|
|
101
101
|
if (Object.prototype.hasOwnProperty.call(this.variables, name)) {
|
|
102
102
|
const variable = this.variables[name];
|
|
103
|
-
if (
|
|
104
|
-
if (!variable.
|
|
105
|
-
variable.
|
|
103
|
+
if (currentMode) {
|
|
104
|
+
if (!variable.modes) {
|
|
105
|
+
variable.modes = {};
|
|
106
106
|
}
|
|
107
|
-
variable.
|
|
107
|
+
variable.modes[currentMode] = variableValue;
|
|
108
108
|
} else {
|
|
109
109
|
variable.value = variableValue.value;
|
|
110
110
|
if (variableValue.type === 'color') {
|
|
@@ -112,11 +112,11 @@ class MasterCSS {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
} else {
|
|
115
|
-
if (
|
|
115
|
+
if (currentMode) {
|
|
116
116
|
const newVariable = {
|
|
117
117
|
type: variableValue.type,
|
|
118
|
-
|
|
119
|
-
[
|
|
118
|
+
modes: {
|
|
119
|
+
[currentMode]: variableValue
|
|
120
120
|
}
|
|
121
121
|
};
|
|
122
122
|
if (variableValue.type === 'color') {
|
|
@@ -163,28 +163,28 @@ class MasterCSS {
|
|
|
163
163
|
if (!Object.prototype.hasOwnProperty.call(unexecutedAliasVariable, name)) {
|
|
164
164
|
unexecutedAliasVariable[name] = {};
|
|
165
165
|
}
|
|
166
|
-
unexecutedAliasVariable[name][
|
|
167
|
-
delete unexecutedAliasVariable[name][
|
|
168
|
-
const [alias,
|
|
166
|
+
unexecutedAliasVariable[name][mode] = ()=>{
|
|
167
|
+
delete unexecutedAliasVariable[name][mode];
|
|
168
|
+
const [alias, aliasMode] = aliasResult[1].split('@');
|
|
169
169
|
if (alias) {
|
|
170
170
|
if (Object.prototype.hasOwnProperty.call(unexecutedAliasVariable, alias)) {
|
|
171
|
-
for (const
|
|
172
|
-
unexecutedAliasVariable[alias][
|
|
171
|
+
for (const mode of Object.keys(unexecutedAliasVariable[alias])){
|
|
172
|
+
unexecutedAliasVariable[alias][mode]?.();
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
const aliasVariable = this.variables[alias];
|
|
176
176
|
if (aliasVariable) {
|
|
177
|
-
if (
|
|
177
|
+
if (aliasMode === undefined && aliasVariable.modes) {
|
|
178
178
|
addVariable(name, {
|
|
179
179
|
type: aliasVariable.type,
|
|
180
180
|
value: aliasVariable.value,
|
|
181
181
|
space: aliasVariable.space
|
|
182
182
|
}, '', aliasResult[2]);
|
|
183
|
-
for(const
|
|
184
|
-
addVariable(name, aliasVariable.
|
|
183
|
+
for(const mode in aliasVariable.modes){
|
|
184
|
+
addVariable(name, aliasVariable.modes[mode], mode, aliasResult[2]);
|
|
185
185
|
}
|
|
186
186
|
} else {
|
|
187
|
-
const variable =
|
|
187
|
+
const variable = aliasMode !== undefined ? aliasVariable.modes?.[aliasMode] : aliasVariable;
|
|
188
188
|
if (variable) {
|
|
189
189
|
const newVariable = {
|
|
190
190
|
type: variable.type,
|
|
@@ -239,13 +239,13 @@ class MasterCSS {
|
|
|
239
239
|
parseVariable(variables[parnetKey], parnetKey);
|
|
240
240
|
}
|
|
241
241
|
for (const name of Object.keys(unexecutedAliasVariable)){
|
|
242
|
-
for (const
|
|
243
|
-
unexecutedAliasVariable[name][
|
|
242
|
+
for (const mode of Object.keys(unexecutedAliasVariable[name])){
|
|
243
|
+
unexecutedAliasVariable[name][mode]?.();
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
|
-
if (
|
|
248
|
-
this.
|
|
247
|
+
if (queries) {
|
|
248
|
+
this.queries = flattenObject.flattenObject(queries);
|
|
249
249
|
}
|
|
250
250
|
if (animations) {
|
|
251
251
|
for(const animationName in animations){
|
|
@@ -415,10 +415,10 @@ class MasterCSS {
|
|
|
415
415
|
*/ refresh(customConfig = this.customConfig) {
|
|
416
416
|
if (!customConfig?.override) {
|
|
417
417
|
// @ts-ignore
|
|
418
|
-
this.config = extendConfig
|
|
418
|
+
this.config = extendConfig(index.config, customConfig);
|
|
419
419
|
} else {
|
|
420
420
|
// @ts-ignore
|
|
421
|
-
this.config = extendConfig
|
|
421
|
+
this.config = extendConfig(customConfig);
|
|
422
422
|
}
|
|
423
423
|
this.resolve();
|
|
424
424
|
this.rules.length = 0;
|
|
@@ -495,15 +495,15 @@ class MasterCSS {
|
|
|
495
495
|
const variable = this.variables[eachVariableName];
|
|
496
496
|
if (!variable.usage) variable.usage = 0;
|
|
497
497
|
if (!--variable.usage) {
|
|
498
|
-
const removeProperty = (
|
|
499
|
-
const nativeRule = this.variablesNativeRules[
|
|
498
|
+
const removeProperty = (mode)=>{
|
|
499
|
+
const nativeRule = this.variablesNativeRules[mode];
|
|
500
500
|
nativeRule.cssRule.style.removeProperty('--' + eachVariableName);
|
|
501
501
|
if (!nativeRule.cssRule.style.length) {
|
|
502
502
|
const variablesRule = this.rules[0];
|
|
503
503
|
const index = variablesRule.natives.indexOf(nativeRule);
|
|
504
504
|
sheet?.deleteRule(index);
|
|
505
505
|
variablesRule.natives.splice(index, 1);
|
|
506
|
-
delete this.variablesNativeRules[
|
|
506
|
+
delete this.variablesNativeRules[mode];
|
|
507
507
|
if (!variablesRule.natives.length) {
|
|
508
508
|
this.rules.splice(0, 1);
|
|
509
509
|
this.variablesNativeRules = {};
|
|
@@ -513,9 +513,9 @@ class MasterCSS {
|
|
|
513
513
|
if (variable.value) {
|
|
514
514
|
removeProperty('');
|
|
515
515
|
}
|
|
516
|
-
if (variable.
|
|
517
|
-
for(const
|
|
518
|
-
removeProperty(
|
|
516
|
+
if (variable.modes) {
|
|
517
|
+
for(const mode in variable.modes){
|
|
518
|
+
removeProperty(mode);
|
|
519
519
|
}
|
|
520
520
|
}
|
|
521
521
|
}
|
|
@@ -578,7 +578,7 @@ class MasterCSS {
|
|
|
578
578
|
* @example <1 <2 <3 ALL >=1 >=2 >=3
|
|
579
579
|
* @description
|
|
580
580
|
*/ const endIndex = this.rules.length - 1;
|
|
581
|
-
const {
|
|
581
|
+
const { at, atToken, order, priority, hasWhere, className } = rule;
|
|
582
582
|
const findIndex = (startIndex, stopCheck, matchCheck)=>{
|
|
583
583
|
let i = startIndex;
|
|
584
584
|
for(; i <= endIndex; i++){
|
|
@@ -590,14 +590,15 @@ class MasterCSS {
|
|
|
590
590
|
};
|
|
591
591
|
let matchStartIndex;
|
|
592
592
|
let matchEndIndex;
|
|
593
|
-
if (
|
|
594
|
-
const mediaStartIndex = this.rules.findIndex((eachRule)=>eachRule.media);
|
|
593
|
+
if (atToken) {
|
|
594
|
+
const mediaStartIndex = this.rules.findIndex((eachRule)=>eachRule.at?.media);
|
|
595
595
|
if (mediaStartIndex === -1) {
|
|
596
596
|
index = endIndex + 1;
|
|
597
597
|
} else {
|
|
598
|
-
const {
|
|
598
|
+
const maxWidthFeature = at.media?.find(({ name })=>name === 'max-width');
|
|
599
|
+
const minWidthFeature = at.media?.find(({ name })=>name === 'min-width');
|
|
599
600
|
if (maxWidthFeature || minWidthFeature) {
|
|
600
|
-
const mediaWidthStartIndex = this.rules.findIndex((eachRule)=>eachRule.media?.
|
|
601
|
+
const mediaWidthStartIndex = this.rules.findIndex((eachRule)=>eachRule.at?.media?.find(({ name })=>name === 'max-width' || name === 'min-width'));
|
|
601
602
|
if (mediaWidthStartIndex === -1) {
|
|
602
603
|
index = endIndex + 1;
|
|
603
604
|
} else {
|
|
@@ -608,10 +609,10 @@ class MasterCSS {
|
|
|
608
609
|
* find 第一個所遇到同樣 feature 且範圍值比自己大的 rule,
|
|
609
610
|
* 並插入在該 rule 之後,讓自己優先被套用
|
|
610
611
|
*/ if (priority === -1) {
|
|
611
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.priority !== -1, (eachRule)=>eachRule.media
|
|
612
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.priority !== -1, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width'));
|
|
612
613
|
matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.priority !== -1);
|
|
613
614
|
} else {
|
|
614
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, undefined, (eachRule)=>eachRule.media
|
|
615
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, undefined, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1);
|
|
615
616
|
matchEndIndex = endIndex;
|
|
616
617
|
}
|
|
617
618
|
if (matchStartIndex !== -1) {
|
|
@@ -620,7 +621,9 @@ class MasterCSS {
|
|
|
620
621
|
const endI = matchStartIndex;
|
|
621
622
|
matchStartIndex = undefined;
|
|
622
623
|
for(; i >= endI; i--){
|
|
623
|
-
const
|
|
624
|
+
const eachRule = this.rules[i];
|
|
625
|
+
const eachMaxWidthFeature = eachRule.at.media?.find(({ name })=>name === 'max-width');
|
|
626
|
+
const eachMinWidthFeature = eachRule.at.media?.find(({ name })=>name === 'min-width');
|
|
624
627
|
const eachRange = eachMaxWidthFeature.value - eachMinWidthFeature.value;
|
|
625
628
|
if (eachRange < range) {
|
|
626
629
|
matchEndIndex = i - 1;
|
|
@@ -634,7 +637,9 @@ class MasterCSS {
|
|
|
634
637
|
if (matchStartIndex !== -1 && matchStartIndex !== undefined) {
|
|
635
638
|
const range = maxWidthFeature.value - minWidthFeature.value;
|
|
636
639
|
for(let i = matchEndIndex; i >= matchStartIndex; i--){
|
|
637
|
-
const
|
|
640
|
+
const eachRule = this.rules[i];
|
|
641
|
+
const eachMaxWidthFeature = eachRule.at.media?.find(({ name })=>name === 'max-width');
|
|
642
|
+
const eachMinWidthFeature = eachRule.at.media?.find(({ name })=>name === 'min-width');
|
|
638
643
|
const eachRange = eachMaxWidthFeature.value - eachMinWidthFeature.value;
|
|
639
644
|
if (eachRange < range) {
|
|
640
645
|
matchEndIndex = i - 1;
|
|
@@ -649,15 +654,15 @@ class MasterCSS {
|
|
|
649
654
|
* find 第一個所遇到同樣 feature 且值比自己大的 rule,
|
|
650
655
|
* 並插入在該 rule 之後,讓自己優先被套用
|
|
651
656
|
*/ if (priority === -1) {
|
|
652
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media
|
|
653
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media
|
|
657
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') || eachRule.priority !== -1, (eachRule)=>!eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width'));
|
|
658
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') || eachRule.priority !== -1);
|
|
654
659
|
} else {
|
|
655
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media
|
|
656
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media
|
|
660
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1, (eachRule)=>!eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1);
|
|
661
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1);
|
|
657
662
|
}
|
|
658
663
|
if (matchStartIndex !== -1) {
|
|
659
664
|
for(let i = matchEndIndex; i >= matchStartIndex; i--){
|
|
660
|
-
const value = this.rules[i].media
|
|
665
|
+
const value = (this.rules[i].at.media?.find(({ name })=>name === 'min-width')).value;
|
|
661
666
|
if (value > minWidthFeature.value) {
|
|
662
667
|
matchEndIndex = i - 1;
|
|
663
668
|
} else if (value < minWidthFeature.value) {
|
|
@@ -671,15 +676,15 @@ class MasterCSS {
|
|
|
671
676
|
* find 第一個所遇到同樣 feature 且值比自己大的 rule,
|
|
672
677
|
* 並插入在該 rule 之後,讓自己優先被套用
|
|
673
678
|
*/ if (priority === -1) {
|
|
674
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media
|
|
675
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media
|
|
679
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'min-width') || eachRule.priority !== -1, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width'));
|
|
680
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'min-width') || eachRule.priority !== -1);
|
|
676
681
|
} else {
|
|
677
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media
|
|
678
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media
|
|
682
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.priority !== -1);
|
|
683
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1);
|
|
679
684
|
}
|
|
680
685
|
if (matchStartIndex !== -1) {
|
|
681
686
|
for(let i = matchEndIndex; i >= matchStartIndex; i--){
|
|
682
|
-
const value = this.rules[i].media
|
|
687
|
+
const value = (this.rules[i].at.media?.find(({ name })=>name === 'max-width')).value;
|
|
683
688
|
if (value < maxWidthFeature.value) {
|
|
684
689
|
matchEndIndex = i - 1;
|
|
685
690
|
} else if (value > maxWidthFeature.value) {
|
|
@@ -693,10 +698,10 @@ class MasterCSS {
|
|
|
693
698
|
} else {
|
|
694
699
|
if (priority === -1) {
|
|
695
700
|
matchStartIndex = mediaStartIndex;
|
|
696
|
-
matchEndIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.media?.
|
|
701
|
+
matchEndIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width') || eachRule.priority !== -1);
|
|
697
702
|
} else {
|
|
698
|
-
matchStartIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.media?.
|
|
699
|
-
matchEndIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.media?.
|
|
703
|
+
matchStartIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width'), (eachRule)=>eachRule.priority !== -1);
|
|
704
|
+
matchEndIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width'));
|
|
700
705
|
}
|
|
701
706
|
}
|
|
702
707
|
}
|
|
@@ -704,10 +709,10 @@ class MasterCSS {
|
|
|
704
709
|
const findStartIndex = Object.keys(this.variablesNativeRules).length ? this.hasKeyframesRule ? 2 : 1 : this.hasKeyframesRule ? 1 : 0;
|
|
705
710
|
if (priority === -1) {
|
|
706
711
|
matchStartIndex = findStartIndex;
|
|
707
|
-
matchEndIndex = findIndex(findStartIndex, (eachRule)=>eachRule.
|
|
712
|
+
matchEndIndex = findIndex(findStartIndex, (eachRule)=>eachRule.atToken || eachRule.priority !== -1);
|
|
708
713
|
} else {
|
|
709
|
-
matchStartIndex = findIndex(findStartIndex, (eachRule)=>eachRule.
|
|
710
|
-
matchEndIndex = findIndex(findStartIndex, (eachRule)=>eachRule.
|
|
714
|
+
matchStartIndex = findIndex(findStartIndex, (eachRule)=>eachRule.atToken, (eachRule)=>eachRule.priority !== -1);
|
|
715
|
+
matchEndIndex = findIndex(findStartIndex, (eachRule)=>eachRule.atToken);
|
|
711
716
|
}
|
|
712
717
|
}
|
|
713
718
|
if (index === undefined && matchEndIndex !== undefined && matchStartIndex !== undefined) {
|
|
@@ -850,23 +855,23 @@ class MasterCSS {
|
|
|
850
855
|
if (variable.usage) {
|
|
851
856
|
variable.usage++;
|
|
852
857
|
} else {
|
|
853
|
-
const addProperty = (
|
|
854
|
-
let nativeRule = this.variablesNativeRules[
|
|
858
|
+
const addProperty = (mode, variableValue)=>{
|
|
859
|
+
let nativeRule = this.variablesNativeRules[mode];
|
|
855
860
|
if (!nativeRule) {
|
|
856
861
|
let cssRule;
|
|
857
862
|
let mediaConditionText;
|
|
858
863
|
let selectorText;
|
|
859
|
-
if (
|
|
860
|
-
switch(this.config.
|
|
864
|
+
if (mode) {
|
|
865
|
+
switch(this.config.modeDriver){
|
|
861
866
|
case 'media':
|
|
862
|
-
mediaConditionText = `@media(prefers-color-scheme:${
|
|
867
|
+
mediaConditionText = `@media(prefers-color-scheme:${mode})`;
|
|
863
868
|
selectorText = ':root';
|
|
864
869
|
break;
|
|
865
870
|
case 'host':
|
|
866
|
-
selectorText = `:host(.${
|
|
871
|
+
selectorText = `:host(.${mode})`;
|
|
867
872
|
break;
|
|
868
873
|
default:
|
|
869
|
-
selectorText = `.${
|
|
874
|
+
selectorText = `.${mode}`;
|
|
870
875
|
break;
|
|
871
876
|
}
|
|
872
877
|
} else {
|
|
@@ -916,7 +921,7 @@ class MasterCSS {
|
|
|
916
921
|
};
|
|
917
922
|
}
|
|
918
923
|
}
|
|
919
|
-
nativeRule = this.pushVariableNativeRule(
|
|
924
|
+
nativeRule = this.pushVariableNativeRule(mode, cssRule);
|
|
920
925
|
}
|
|
921
926
|
const propertyName = '--' + eachVariableName;
|
|
922
927
|
if (!initializing || !nativeRule.cssRule.style.getPropertyValue(propertyName)) {
|
|
@@ -926,9 +931,9 @@ class MasterCSS {
|
|
|
926
931
|
if (variable.value) {
|
|
927
932
|
addProperty('', variable);
|
|
928
933
|
}
|
|
929
|
-
if (variable.
|
|
930
|
-
for(const
|
|
931
|
-
addProperty(
|
|
934
|
+
if (variable.modes) {
|
|
935
|
+
for(const mode in variable.modes){
|
|
936
|
+
addProperty(mode, variable.modes[mode]);
|
|
932
937
|
}
|
|
933
938
|
}
|
|
934
939
|
variable.usage = 1;
|
|
@@ -936,7 +941,7 @@ class MasterCSS {
|
|
|
936
941
|
}
|
|
937
942
|
}
|
|
938
943
|
}
|
|
939
|
-
pushVariableNativeRule(
|
|
944
|
+
pushVariableNativeRule(mode, variableCSSRule) {
|
|
940
945
|
if (!Object.keys(this.variablesNativeRules).length) {
|
|
941
946
|
this.variablesNativeRules = {};
|
|
942
947
|
const newRule = {
|
|
@@ -965,7 +970,7 @@ class MasterCSS {
|
|
|
965
970
|
return prefix + properties.join(';') + suffix;
|
|
966
971
|
}
|
|
967
972
|
};
|
|
968
|
-
this.rules[0].natives.push(this.variablesNativeRules[
|
|
973
|
+
this.rules[0].natives.push(this.variablesNativeRules[mode] = nativeRule);
|
|
969
974
|
return nativeRule;
|
|
970
975
|
}
|
|
971
976
|
}
|
package/dist/core.d.ts
CHANGED
|
@@ -16,8 +16,8 @@ export type Variable = Omit<VariableValue, 'value' | 'space'> & {
|
|
|
16
16
|
value?: any;
|
|
17
17
|
space?: any;
|
|
18
18
|
usage?: number;
|
|
19
|
-
|
|
20
|
-
[
|
|
19
|
+
modes?: {
|
|
20
|
+
[mode: string]: VariableValue;
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
23
|
export default class MasterCSS {
|
|
@@ -76,7 +76,7 @@ export default class MasterCSS {
|
|
|
76
76
|
get text(): string;
|
|
77
77
|
handleRuleWithAnimationNames(rule: Rule, initializing?: boolean): void;
|
|
78
78
|
handleRuleWithVariableNames(rule: Rule, initializing?: boolean): void;
|
|
79
|
-
pushVariableNativeRule(
|
|
79
|
+
pushVariableNativeRule(mode: string, variableCSSRule: CSSStyleRule): NativeRule;
|
|
80
80
|
}
|
|
81
81
|
export declare const masterCSSs: MasterCSS[];
|
|
82
82
|
export default interface MasterCSS {
|
|
@@ -85,7 +85,7 @@ export default interface MasterCSS {
|
|
|
85
85
|
stylesBy: Record<string, string[]>;
|
|
86
86
|
selectors: Record<string, [RegExp, string[]][]>;
|
|
87
87
|
variables: Record<string, Variable>;
|
|
88
|
-
|
|
88
|
+
queries: Record<string, string | number>;
|
|
89
89
|
variablesNativeRules: Record<string, NativeRule>;
|
|
90
90
|
hasKeyframesRule: boolean;
|
|
91
91
|
animations: Record<string, AnimationDefinitions & {
|