@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.
Files changed (47) hide show
  1. package/dist/config/index.cjs +4 -4
  2. package/dist/config/index.d.ts +4 -4
  3. package/dist/config/index.mjs +4 -4
  4. package/dist/config/queries.cjs +13 -0
  5. package/dist/config/queries.d.ts +18 -0
  6. package/dist/config/queries.mjs +11 -0
  7. package/dist/config/variables.d.ts +0 -12
  8. package/dist/config/variables.mjs +2 -2
  9. package/dist/core.cjs +80 -75
  10. package/dist/core.d.ts +4 -4
  11. package/dist/core.mjs +76 -71
  12. package/dist/functions/are-rule-modes-equal.cjs +7 -0
  13. package/dist/functions/are-rule-modes-equal.d.ts +2 -0
  14. package/dist/functions/are-rule-modes-equal.mjs +5 -0
  15. package/dist/functions/are-rule-queries-equal.cjs +22 -0
  16. package/dist/functions/are-rule-queries-equal.d.ts +2 -0
  17. package/dist/functions/are-rule-queries-equal.mjs +20 -0
  18. package/dist/functions/are-rule-selectors-equal.cjs +29 -0
  19. package/dist/functions/are-rule-selectors-equal.d.ts +2 -0
  20. package/dist/functions/are-rule-selectors-equal.mjs +27 -0
  21. package/dist/functions/are-rule-states-equal.cjs +11 -0
  22. package/dist/functions/are-rule-states-equal.d.ts +2 -0
  23. package/dist/functions/are-rule-states-equal.mjs +9 -0
  24. package/dist/functions/are-rules-duplicated.cjs +17 -0
  25. package/dist/functions/are-rules-duplicated.d.ts +2 -0
  26. package/dist/functions/are-rules-duplicated.mjs +15 -0
  27. package/dist/{utils → functions}/extend-config.cjs +27 -14
  28. package/dist/functions/extend-config.d.ts +2 -0
  29. package/dist/{utils → functions}/extend-config.mjs +27 -14
  30. package/dist/functions/reorder-for-readable-classes.cjs +7 -7
  31. package/dist/functions/reorder-for-readable-classes.mjs +7 -7
  32. package/dist/index.cjs +16 -6
  33. package/dist/index.d.ts +7 -2
  34. package/dist/index.mjs +8 -3
  35. package/dist/rule.cjs +118 -90
  36. package/dist/rule.d.ts +28 -3
  37. package/dist/rule.mjs +118 -90
  38. package/dist/tokens/screen-sizes.cjs +2 -2
  39. package/dist/tokens/screen-sizes.mjs +2 -2
  40. package/package.json +1 -1
  41. package/dist/config/media-queries.cjs +0 -7
  42. package/dist/config/media-queries.d.ts +0 -1
  43. package/dist/config/media-queries.mjs +0 -1
  44. package/dist/functions/transform-color-with-opacity.cjs +0 -9
  45. package/dist/functions/transform-color-with-opacity.d.ts +0 -1
  46. package/dist/functions/transform-color-with-opacity.mjs +0 -7
  47. package/dist/utils/extend-config.d.ts +0 -2
@@ -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
- mediaQueries: screenSizes,
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
- themeDriver: 'class'
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;
@@ -1,4 +1,4 @@
1
- import mediaQueries from './media-queries';
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, mediaQueries, selectors, semantics, rules, functions, animations, variables };
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
- mediaQueries?: MediaQueryDefinitions;
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
- themeDriver?: 'class' | 'media' | 'host';
67
+ modeDriver?: 'class' | 'media' | 'host';
68
68
  }
@@ -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
- mediaQueries,
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
- themeDriver: 'class'
22
+ modeDriver: 'class'
23
23
  };
24
24
 
25
- export { animations, config, functions, mediaQueries, rules, selectors, semantics, variables };
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 };
@@ -109,24 +109,12 @@ declare const variables: {
109
109
  '@light': string;
110
110
  '@dark': string;
111
111
  };
112
- canvas: {
113
- '@light': string;
114
- '@dark': string;
115
- };
116
- surface: {
117
- '@light': string;
118
- '@dark': string;
119
- };
120
112
  invert: {
121
113
  '@light': string;
122
114
  '@dark': string;
123
115
  };
124
116
  white: string;
125
117
  black: string;
126
- frame: {
127
- '@light': string;
128
- '@dark': string;
129
- };
130
118
  gray: {
131
119
  '5': string;
132
120
  '10': string;
@@ -1,5 +1,5 @@
1
1
  import colors from '@master/colors';
2
- import mediaQueries from '../tokens/screen-sizes.mjs';
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: mediaQueries,
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('./utils/extend-config.cjs');
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.extendConfig(index.config, customConfig);
29
+ this.config = extendConfig(index.config, customConfig);
30
30
  } else {
31
- this.config = extendConfig.extendConfig(customConfig);
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.mediaQueries = {};
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, mediaQueries, rules, animations } = this.config;
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, theme)=>{
85
+ const parseVariable = (variable, name, mode)=>{
86
86
  if (!variable) return;
87
- const addVariable = (name, variableValue, replacedTheme, alpha)=>{
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 currentTheme = replacedTheme ?? theme;
100
- if (currentTheme !== undefined) {
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 (currentTheme) {
104
- if (!variable.themes) {
105
- variable.themes = {};
103
+ if (currentMode) {
104
+ if (!variable.modes) {
105
+ variable.modes = {};
106
106
  }
107
- variable.themes[currentTheme] = variableValue;
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 (currentTheme) {
115
+ if (currentMode) {
116
116
  const newVariable = {
117
117
  type: variableValue.type,
118
- themes: {
119
- [currentTheme]: variableValue
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][theme] = ()=>{
167
- delete unexecutedAliasVariable[name][theme];
168
- const [alias, aliasTheme] = aliasResult[1].split('@');
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 theme of Object.keys(unexecutedAliasVariable[alias])){
172
- unexecutedAliasVariable[alias][theme]?.();
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 (aliasTheme === undefined && aliasVariable.themes) {
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 theme in aliasVariable.themes){
184
- addVariable(name, aliasVariable.themes[theme], theme, aliasResult[2]);
183
+ for(const mode in aliasVariable.modes){
184
+ addVariable(name, aliasVariable.modes[mode], mode, aliasResult[2]);
185
185
  }
186
186
  } else {
187
- const variable = aliasTheme !== undefined ? aliasVariable.themes?.[aliasTheme] : aliasVariable;
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 theme of Object.keys(unexecutedAliasVariable[name])){
243
- unexecutedAliasVariable[name][theme]?.();
242
+ for (const mode of Object.keys(unexecutedAliasVariable[name])){
243
+ unexecutedAliasVariable[name][mode]?.();
244
244
  }
245
245
  }
246
246
  }
247
- if (mediaQueries) {
248
- this.mediaQueries = flattenObject.flattenObject(mediaQueries);
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.extendConfig(index.config, customConfig);
418
+ this.config = extendConfig(index.config, customConfig);
419
419
  } else {
420
420
  // @ts-ignore
421
- this.config = extendConfig.extendConfig(customConfig);
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 = (theme)=>{
499
- const nativeRule = this.variablesNativeRules[theme];
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[theme];
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.themes) {
517
- for(const theme in variable.themes){
518
- removeProperty(theme);
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 { media, order, priority, hasWhere, className } = rule;
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 (media) {
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 { 'max-width': maxWidthFeature, 'min-width': minWidthFeature } = media.features;
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?.features['max-width'] || eachRule.media?.features['min-width']);
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.features['max-width'] && eachRule.media.features['min-width']);
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.features['max-width'] && eachRule.media.features['min-width'] && eachRule.priority !== -1);
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 { 'max-width': eachMaxWidthFeature, 'min-width': eachMinWidthFeature } = this.rules[i].media.features;
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 { 'max-width': eachMaxWidthFeature, 'min-width': eachMinWidthFeature } = this.rules[i].media.features;
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.features['max-width'] && eachRule.media.features['min-width'] || eachRule.priority !== -1, (eachRule)=>!eachRule.media.features['max-width'] && eachRule.media.features['min-width']);
653
- matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media.features['max-width'] && eachRule.media.features['min-width'] || eachRule.priority !== -1);
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.features['max-width'] && eachRule.media.features['min-width'] && eachRule.priority !== -1, (eachRule)=>!eachRule.media.features['max-width'] && eachRule.media.features['min-width'] && eachRule.priority !== -1);
656
- matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media.features['max-width'] && eachRule.media.features['min-width'] && eachRule.priority !== -1);
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.features['min-width'].value;
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.features['min-width'] || eachRule.priority !== -1, (eachRule)=>eachRule.media.features['max-width']);
675
- matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media.features['min-width'] || eachRule.priority !== -1);
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.features['min-width'] && eachRule.priority !== -1, (eachRule)=>eachRule.media.features['max-width'] && eachRule.priority !== -1);
678
- matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media.features['min-width'] && eachRule.priority !== -1);
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.features['max-width'].value;
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?.features['max-width'] || eachRule.media?.features['min-width'] || eachRule.priority !== -1);
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?.features['max-width'] || eachRule.media?.features['min-width'], (eachRule)=>eachRule.priority !== -1);
699
- matchEndIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.media?.features['max-width'] || eachRule.media?.features['min-width']);
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.media || eachRule.priority !== -1);
712
+ matchEndIndex = findIndex(findStartIndex, (eachRule)=>eachRule.atToken || eachRule.priority !== -1);
708
713
  } else {
709
- matchStartIndex = findIndex(findStartIndex, (eachRule)=>eachRule.media, (eachRule)=>eachRule.priority !== -1);
710
- matchEndIndex = findIndex(findStartIndex, (eachRule)=>eachRule.media);
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 = (theme, variableValue)=>{
854
- let nativeRule = this.variablesNativeRules[theme];
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 (theme) {
860
- switch(this.config.themeDriver){
864
+ if (mode) {
865
+ switch(this.config.modeDriver){
861
866
  case 'media':
862
- mediaConditionText = `@media(prefers-color-scheme:${theme})`;
867
+ mediaConditionText = `@media(prefers-color-scheme:${mode})`;
863
868
  selectorText = ':root';
864
869
  break;
865
870
  case 'host':
866
- selectorText = `:host(.${theme})`;
871
+ selectorText = `:host(.${mode})`;
867
872
  break;
868
873
  default:
869
- selectorText = `.${theme}`;
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(theme, cssRule);
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.themes) {
930
- for(const theme in variable.themes){
931
- addProperty(theme, variable.themes[theme]);
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(theme, variableCSSRule) {
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[theme] = nativeRule);
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
- themes?: {
20
- [theme: string]: VariableValue;
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(theme: string, variableCSSRule: CSSStyleRule): NativeRule;
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
- mediaQueries: Record<string, string | number>;
88
+ queries: Record<string, string | number>;
89
89
  variablesNativeRules: Record<string, NativeRule>;
90
90
  hasKeyframesRule: boolean;
91
91
  animations: Record<string, AnimationDefinitions & {