@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.
Files changed (46) 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.mjs +2 -2
  8. package/dist/core.cjs +80 -75
  9. package/dist/core.d.ts +4 -4
  10. package/dist/core.mjs +76 -71
  11. package/dist/functions/are-rule-modes-equal.cjs +7 -0
  12. package/dist/functions/are-rule-modes-equal.d.ts +2 -0
  13. package/dist/functions/are-rule-modes-equal.mjs +5 -0
  14. package/dist/functions/are-rule-queries-equal.cjs +22 -0
  15. package/dist/functions/are-rule-queries-equal.d.ts +2 -0
  16. package/dist/functions/are-rule-queries-equal.mjs +20 -0
  17. package/dist/functions/are-rule-selectors-equal.cjs +29 -0
  18. package/dist/functions/are-rule-selectors-equal.d.ts +2 -0
  19. package/dist/functions/are-rule-selectors-equal.mjs +27 -0
  20. package/dist/functions/are-rule-states-equal.cjs +11 -0
  21. package/dist/functions/are-rule-states-equal.d.ts +2 -0
  22. package/dist/functions/are-rule-states-equal.mjs +9 -0
  23. package/dist/functions/are-rules-duplicated.cjs +17 -0
  24. package/dist/functions/are-rules-duplicated.d.ts +2 -0
  25. package/dist/functions/are-rules-duplicated.mjs +15 -0
  26. package/dist/{utils → functions}/extend-config.cjs +27 -14
  27. package/dist/functions/extend-config.d.ts +2 -0
  28. package/dist/{utils → functions}/extend-config.mjs +27 -14
  29. package/dist/functions/reorder-for-readable-classes.cjs +7 -7
  30. package/dist/functions/reorder-for-readable-classes.mjs +7 -7
  31. package/dist/index.cjs +16 -6
  32. package/dist/index.d.ts +7 -2
  33. package/dist/index.mjs +8 -3
  34. package/dist/rule.cjs +118 -90
  35. package/dist/rule.d.ts +28 -3
  36. package/dist/rule.mjs +118 -90
  37. package/dist/tokens/screen-sizes.cjs +2 -2
  38. package/dist/tokens/screen-sizes.mjs +2 -2
  39. package/package.json +1 -1
  40. package/dist/config/media-queries.cjs +0 -7
  41. package/dist/config/media-queries.d.ts +0 -1
  42. package/dist/config/media-queries.mjs +0 -1
  43. package/dist/functions/transform-color-with-opacity.cjs +0 -9
  44. package/dist/functions/transform-color-with-opacity.d.ts +0 -1
  45. package/dist/functions/transform-color-with-opacity.mjs +0 -7
  46. package/dist/utils/extend-config.d.ts +0 -2
package/dist/core.mjs CHANGED
@@ -3,7 +3,7 @@ import { config } from './config/index.mjs';
3
3
  import { Layer } from './layer.mjs';
4
4
  import { hexToRgb } from './utils/hex-to-rgb.mjs';
5
5
  import { flattenObject } from './utils/flatten-object.mjs';
6
- import { extendConfig } from './utils/extend-config.mjs';
6
+ import extendConfig from './functions/extend-config.mjs';
7
7
 
8
8
  class MasterCSS {
9
9
  customConfig;
@@ -36,7 +36,7 @@ class MasterCSS {
36
36
  this.stylesBy = {};
37
37
  this.selectors = {};
38
38
  this.variables = {};
39
- this.mediaQueries = {};
39
+ this.queries = {};
40
40
  this.animations = {};
41
41
  this.RegisteredRules.length = 0;
42
42
  this.RegisteredSemanticRules.length = 0;
@@ -47,7 +47,7 @@ class MasterCSS {
47
47
  currentColor: undefined,
48
48
  transparent: undefined
49
49
  };
50
- const { styles, selectors, variables, semantics, mediaQueries, rules, animations } = this.config;
50
+ const { styles, selectors, variables, semantics, queries, rules, animations } = this.config;
51
51
  function escapeString(str) {
52
52
  return str.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
53
53
  }
@@ -78,9 +78,9 @@ class MasterCSS {
78
78
  }
79
79
  if (variables) {
80
80
  const unexecutedAliasVariable = {};
81
- const parseVariable = (variable, name, theme)=>{
81
+ const parseVariable = (variable, name, mode)=>{
82
82
  if (!variable) return;
83
- const addVariable = (name, variableValue, replacedTheme, alpha)=>{
83
+ const addVariable = (name, variableValue, replacedMode, alpha)=>{
84
84
  if (variableValue === undefined) return;
85
85
  if (variableValue.type === 'color') {
86
86
  if (alpha) {
@@ -92,15 +92,15 @@ class MasterCSS {
92
92
  }
93
93
  colorVariableNames[name] = undefined;
94
94
  }
95
- const currentTheme = replacedTheme ?? theme;
96
- if (currentTheme !== undefined) {
95
+ const currentMode = replacedMode ?? mode;
96
+ if (currentMode !== undefined) {
97
97
  if (Object.prototype.hasOwnProperty.call(this.variables, name)) {
98
98
  const variable = this.variables[name];
99
- if (currentTheme) {
100
- if (!variable.themes) {
101
- variable.themes = {};
99
+ if (currentMode) {
100
+ if (!variable.modes) {
101
+ variable.modes = {};
102
102
  }
103
- variable.themes[currentTheme] = variableValue;
103
+ variable.modes[currentMode] = variableValue;
104
104
  } else {
105
105
  variable.value = variableValue.value;
106
106
  if (variableValue.type === 'color') {
@@ -108,11 +108,11 @@ class MasterCSS {
108
108
  }
109
109
  }
110
110
  } else {
111
- if (currentTheme) {
111
+ if (currentMode) {
112
112
  const newVariable = {
113
113
  type: variableValue.type,
114
- themes: {
115
- [currentTheme]: variableValue
114
+ modes: {
115
+ [currentMode]: variableValue
116
116
  }
117
117
  };
118
118
  if (variableValue.type === 'color') {
@@ -159,28 +159,28 @@ class MasterCSS {
159
159
  if (!Object.prototype.hasOwnProperty.call(unexecutedAliasVariable, name)) {
160
160
  unexecutedAliasVariable[name] = {};
161
161
  }
162
- unexecutedAliasVariable[name][theme] = ()=>{
163
- delete unexecutedAliasVariable[name][theme];
164
- const [alias, aliasTheme] = aliasResult[1].split('@');
162
+ unexecutedAliasVariable[name][mode] = ()=>{
163
+ delete unexecutedAliasVariable[name][mode];
164
+ const [alias, aliasMode] = aliasResult[1].split('@');
165
165
  if (alias) {
166
166
  if (Object.prototype.hasOwnProperty.call(unexecutedAliasVariable, alias)) {
167
- for (const theme of Object.keys(unexecutedAliasVariable[alias])){
168
- unexecutedAliasVariable[alias][theme]?.();
167
+ for (const mode of Object.keys(unexecutedAliasVariable[alias])){
168
+ unexecutedAliasVariable[alias][mode]?.();
169
169
  }
170
170
  }
171
171
  const aliasVariable = this.variables[alias];
172
172
  if (aliasVariable) {
173
- if (aliasTheme === undefined && aliasVariable.themes) {
173
+ if (aliasMode === undefined && aliasVariable.modes) {
174
174
  addVariable(name, {
175
175
  type: aliasVariable.type,
176
176
  value: aliasVariable.value,
177
177
  space: aliasVariable.space
178
178
  }, '', aliasResult[2]);
179
- for(const theme in aliasVariable.themes){
180
- addVariable(name, aliasVariable.themes[theme], theme, aliasResult[2]);
179
+ for(const mode in aliasVariable.modes){
180
+ addVariable(name, aliasVariable.modes[mode], mode, aliasResult[2]);
181
181
  }
182
182
  } else {
183
- const variable = aliasTheme !== undefined ? aliasVariable.themes?.[aliasTheme] : aliasVariable;
183
+ const variable = aliasMode !== undefined ? aliasVariable.modes?.[aliasMode] : aliasVariable;
184
184
  if (variable) {
185
185
  const newVariable = {
186
186
  type: variable.type,
@@ -235,13 +235,13 @@ class MasterCSS {
235
235
  parseVariable(variables[parnetKey], parnetKey);
236
236
  }
237
237
  for (const name of Object.keys(unexecutedAliasVariable)){
238
- for (const theme of Object.keys(unexecutedAliasVariable[name])){
239
- unexecutedAliasVariable[name][theme]?.();
238
+ for (const mode of Object.keys(unexecutedAliasVariable[name])){
239
+ unexecutedAliasVariable[name][mode]?.();
240
240
  }
241
241
  }
242
242
  }
243
- if (mediaQueries) {
244
- this.mediaQueries = flattenObject(mediaQueries);
243
+ if (queries) {
244
+ this.queries = flattenObject(queries);
245
245
  }
246
246
  if (animations) {
247
247
  for(const animationName in animations){
@@ -491,15 +491,15 @@ class MasterCSS {
491
491
  const variable = this.variables[eachVariableName];
492
492
  if (!variable.usage) variable.usage = 0;
493
493
  if (!--variable.usage) {
494
- const removeProperty = (theme)=>{
495
- const nativeRule = this.variablesNativeRules[theme];
494
+ const removeProperty = (mode)=>{
495
+ const nativeRule = this.variablesNativeRules[mode];
496
496
  nativeRule.cssRule.style.removeProperty('--' + eachVariableName);
497
497
  if (!nativeRule.cssRule.style.length) {
498
498
  const variablesRule = this.rules[0];
499
499
  const index = variablesRule.natives.indexOf(nativeRule);
500
500
  sheet?.deleteRule(index);
501
501
  variablesRule.natives.splice(index, 1);
502
- delete this.variablesNativeRules[theme];
502
+ delete this.variablesNativeRules[mode];
503
503
  if (!variablesRule.natives.length) {
504
504
  this.rules.splice(0, 1);
505
505
  this.variablesNativeRules = {};
@@ -509,9 +509,9 @@ class MasterCSS {
509
509
  if (variable.value) {
510
510
  removeProperty('');
511
511
  }
512
- if (variable.themes) {
513
- for(const theme in variable.themes){
514
- removeProperty(theme);
512
+ if (variable.modes) {
513
+ for(const mode in variable.modes){
514
+ removeProperty(mode);
515
515
  }
516
516
  }
517
517
  }
@@ -574,7 +574,7 @@ class MasterCSS {
574
574
  * @example <1 <2 <3 ALL >=1 >=2 >=3
575
575
  * @description
576
576
  */ const endIndex = this.rules.length - 1;
577
- const { media, order, priority, hasWhere, className } = rule;
577
+ const { at, atToken, order, priority, hasWhere, className } = rule;
578
578
  const findIndex = (startIndex, stopCheck, matchCheck)=>{
579
579
  let i = startIndex;
580
580
  for(; i <= endIndex; i++){
@@ -586,14 +586,15 @@ class MasterCSS {
586
586
  };
587
587
  let matchStartIndex;
588
588
  let matchEndIndex;
589
- if (media) {
590
- const mediaStartIndex = this.rules.findIndex((eachRule)=>eachRule.media);
589
+ if (atToken) {
590
+ const mediaStartIndex = this.rules.findIndex((eachRule)=>eachRule.at?.media);
591
591
  if (mediaStartIndex === -1) {
592
592
  index = endIndex + 1;
593
593
  } else {
594
- const { 'max-width': maxWidthFeature, 'min-width': minWidthFeature } = media.features;
594
+ const maxWidthFeature = at.media?.find(({ name })=>name === 'max-width');
595
+ const minWidthFeature = at.media?.find(({ name })=>name === 'min-width');
595
596
  if (maxWidthFeature || minWidthFeature) {
596
- const mediaWidthStartIndex = this.rules.findIndex((eachRule)=>eachRule.media?.features['max-width'] || eachRule.media?.features['min-width']);
597
+ const mediaWidthStartIndex = this.rules.findIndex((eachRule)=>eachRule.at?.media?.find(({ name })=>name === 'max-width' || name === 'min-width'));
597
598
  if (mediaWidthStartIndex === -1) {
598
599
  index = endIndex + 1;
599
600
  } else {
@@ -604,10 +605,10 @@ class MasterCSS {
604
605
  * find 第一個所遇到同樣 feature 且範圍值比自己大的 rule,
605
606
  * 並插入在該 rule 之後,讓自己優先被套用
606
607
  */ if (priority === -1) {
607
- matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.priority !== -1, (eachRule)=>eachRule.media.features['max-width'] && eachRule.media.features['min-width']);
608
+ matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.priority !== -1, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width'));
608
609
  matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.priority !== -1);
609
610
  } else {
610
- matchStartIndex = findIndex(mediaWidthStartIndex, undefined, (eachRule)=>eachRule.media.features['max-width'] && eachRule.media.features['min-width'] && eachRule.priority !== -1);
611
+ matchStartIndex = findIndex(mediaWidthStartIndex, undefined, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1);
611
612
  matchEndIndex = endIndex;
612
613
  }
613
614
  if (matchStartIndex !== -1) {
@@ -616,7 +617,9 @@ class MasterCSS {
616
617
  const endI = matchStartIndex;
617
618
  matchStartIndex = undefined;
618
619
  for(; i >= endI; i--){
619
- const { 'max-width': eachMaxWidthFeature, 'min-width': eachMinWidthFeature } = this.rules[i].media.features;
620
+ const eachRule = this.rules[i];
621
+ const eachMaxWidthFeature = eachRule.at.media?.find(({ name })=>name === 'max-width');
622
+ const eachMinWidthFeature = eachRule.at.media?.find(({ name })=>name === 'min-width');
620
623
  const eachRange = eachMaxWidthFeature.value - eachMinWidthFeature.value;
621
624
  if (eachRange < range) {
622
625
  matchEndIndex = i - 1;
@@ -630,7 +633,9 @@ class MasterCSS {
630
633
  if (matchStartIndex !== -1 && matchStartIndex !== undefined) {
631
634
  const range = maxWidthFeature.value - minWidthFeature.value;
632
635
  for(let i = matchEndIndex; i >= matchStartIndex; i--){
633
- const { 'max-width': eachMaxWidthFeature, 'min-width': eachMinWidthFeature } = this.rules[i].media.features;
636
+ const eachRule = this.rules[i];
637
+ const eachMaxWidthFeature = eachRule.at.media?.find(({ name })=>name === 'max-width');
638
+ const eachMinWidthFeature = eachRule.at.media?.find(({ name })=>name === 'min-width');
634
639
  const eachRange = eachMaxWidthFeature.value - eachMinWidthFeature.value;
635
640
  if (eachRange < range) {
636
641
  matchEndIndex = i - 1;
@@ -645,15 +650,15 @@ class MasterCSS {
645
650
  * find 第一個所遇到同樣 feature 且值比自己大的 rule,
646
651
  * 並插入在該 rule 之後,讓自己優先被套用
647
652
  */ if (priority === -1) {
648
- 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']);
649
- matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media.features['max-width'] && eachRule.media.features['min-width'] || eachRule.priority !== -1);
653
+ 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'));
654
+ matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') || eachRule.priority !== -1);
650
655
  } else {
651
- 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);
652
- matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media.features['max-width'] && eachRule.media.features['min-width'] && eachRule.priority !== -1);
656
+ 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);
657
+ matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width') && eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1);
653
658
  }
654
659
  if (matchStartIndex !== -1) {
655
660
  for(let i = matchEndIndex; i >= matchStartIndex; i--){
656
- const value = this.rules[i].media.features['min-width'].value;
661
+ const value = (this.rules[i].at.media?.find(({ name })=>name === 'min-width')).value;
657
662
  if (value > minWidthFeature.value) {
658
663
  matchEndIndex = i - 1;
659
664
  } else if (value < minWidthFeature.value) {
@@ -667,15 +672,15 @@ class MasterCSS {
667
672
  * find 第一個所遇到同樣 feature 且值比自己大的 rule,
668
673
  * 並插入在該 rule 之後,讓自己優先被套用
669
674
  */ if (priority === -1) {
670
- matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media.features['min-width'] || eachRule.priority !== -1, (eachRule)=>eachRule.media.features['max-width']);
671
- matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media.features['min-width'] || eachRule.priority !== -1);
675
+ matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'min-width') || eachRule.priority !== -1, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width'));
676
+ matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'min-width') || eachRule.priority !== -1);
672
677
  } else {
673
- matchStartIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media.features['min-width'] && eachRule.priority !== -1, (eachRule)=>eachRule.media.features['max-width'] && eachRule.priority !== -1);
674
- matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.media.features['min-width'] && eachRule.priority !== -1);
678
+ 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);
679
+ matchEndIndex = findIndex(mediaWidthStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'min-width') && eachRule.priority !== -1);
675
680
  }
676
681
  if (matchStartIndex !== -1) {
677
682
  for(let i = matchEndIndex; i >= matchStartIndex; i--){
678
- const value = this.rules[i].media.features['max-width'].value;
683
+ const value = (this.rules[i].at.media?.find(({ name })=>name === 'max-width')).value;
679
684
  if (value < maxWidthFeature.value) {
680
685
  matchEndIndex = i - 1;
681
686
  } else if (value > maxWidthFeature.value) {
@@ -689,10 +694,10 @@ class MasterCSS {
689
694
  } else {
690
695
  if (priority === -1) {
691
696
  matchStartIndex = mediaStartIndex;
692
- matchEndIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.media?.features['max-width'] || eachRule.media?.features['min-width'] || eachRule.priority !== -1);
697
+ matchEndIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width') || eachRule.priority !== -1);
693
698
  } else {
694
- matchStartIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.media?.features['max-width'] || eachRule.media?.features['min-width'], (eachRule)=>eachRule.priority !== -1);
695
- matchEndIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.media?.features['max-width'] || eachRule.media?.features['min-width']);
699
+ matchStartIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width'), (eachRule)=>eachRule.priority !== -1);
700
+ matchEndIndex = findIndex(mediaStartIndex, (eachRule)=>eachRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width'));
696
701
  }
697
702
  }
698
703
  }
@@ -700,10 +705,10 @@ class MasterCSS {
700
705
  const findStartIndex = Object.keys(this.variablesNativeRules).length ? this.hasKeyframesRule ? 2 : 1 : this.hasKeyframesRule ? 1 : 0;
701
706
  if (priority === -1) {
702
707
  matchStartIndex = findStartIndex;
703
- matchEndIndex = findIndex(findStartIndex, (eachRule)=>eachRule.media || eachRule.priority !== -1);
708
+ matchEndIndex = findIndex(findStartIndex, (eachRule)=>eachRule.atToken || eachRule.priority !== -1);
704
709
  } else {
705
- matchStartIndex = findIndex(findStartIndex, (eachRule)=>eachRule.media, (eachRule)=>eachRule.priority !== -1);
706
- matchEndIndex = findIndex(findStartIndex, (eachRule)=>eachRule.media);
710
+ matchStartIndex = findIndex(findStartIndex, (eachRule)=>eachRule.atToken, (eachRule)=>eachRule.priority !== -1);
711
+ matchEndIndex = findIndex(findStartIndex, (eachRule)=>eachRule.atToken);
707
712
  }
708
713
  }
709
714
  if (index === undefined && matchEndIndex !== undefined && matchStartIndex !== undefined) {
@@ -846,23 +851,23 @@ class MasterCSS {
846
851
  if (variable.usage) {
847
852
  variable.usage++;
848
853
  } else {
849
- const addProperty = (theme, variableValue)=>{
850
- let nativeRule = this.variablesNativeRules[theme];
854
+ const addProperty = (mode, variableValue)=>{
855
+ let nativeRule = this.variablesNativeRules[mode];
851
856
  if (!nativeRule) {
852
857
  let cssRule;
853
858
  let mediaConditionText;
854
859
  let selectorText;
855
- if (theme) {
856
- switch(this.config.themeDriver){
860
+ if (mode) {
861
+ switch(this.config.modeDriver){
857
862
  case 'media':
858
- mediaConditionText = `@media(prefers-color-scheme:${theme})`;
863
+ mediaConditionText = `@media(prefers-color-scheme:${mode})`;
859
864
  selectorText = ':root';
860
865
  break;
861
866
  case 'host':
862
- selectorText = `:host(.${theme})`;
867
+ selectorText = `:host(.${mode})`;
863
868
  break;
864
869
  default:
865
- selectorText = `.${theme}`;
870
+ selectorText = `.${mode}`;
866
871
  break;
867
872
  }
868
873
  } else {
@@ -912,7 +917,7 @@ class MasterCSS {
912
917
  };
913
918
  }
914
919
  }
915
- nativeRule = this.pushVariableNativeRule(theme, cssRule);
920
+ nativeRule = this.pushVariableNativeRule(mode, cssRule);
916
921
  }
917
922
  const propertyName = '--' + eachVariableName;
918
923
  if (!initializing || !nativeRule.cssRule.style.getPropertyValue(propertyName)) {
@@ -922,9 +927,9 @@ class MasterCSS {
922
927
  if (variable.value) {
923
928
  addProperty('', variable);
924
929
  }
925
- if (variable.themes) {
926
- for(const theme in variable.themes){
927
- addProperty(theme, variable.themes[theme]);
930
+ if (variable.modes) {
931
+ for(const mode in variable.modes){
932
+ addProperty(mode, variable.modes[mode]);
928
933
  }
929
934
  }
930
935
  variable.usage = 1;
@@ -932,7 +937,7 @@ class MasterCSS {
932
937
  }
933
938
  }
934
939
  }
935
- pushVariableNativeRule(theme, variableCSSRule) {
940
+ pushVariableNativeRule(mode, variableCSSRule) {
936
941
  if (!Object.keys(this.variablesNativeRules).length) {
937
942
  this.variablesNativeRules = {};
938
943
  const newRule = {
@@ -961,7 +966,7 @@ class MasterCSS {
961
966
  return prefix + properties.join(';') + suffix;
962
967
  }
963
968
  };
964
- this.rules[0].natives.push(this.variablesNativeRules[theme] = nativeRule);
969
+ this.rules[0].natives.push(this.variablesNativeRules[mode] = nativeRule);
965
970
  return nativeRule;
966
971
  }
967
972
  }
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ function areRuleModesEqual(aRule, bRule) {
4
+ return aRule.mode === bRule.mode;
5
+ }
6
+
7
+ module.exports = areRuleModesEqual;
@@ -0,0 +1,2 @@
1
+ import type { Rule } from '../rule';
2
+ export default function areRuleModesEqual(aRule: Rule, bRule: Rule): boolean;
@@ -0,0 +1,5 @@
1
+ function areRuleModesEqual(aRule, bRule) {
2
+ return aRule.mode === bRule.mode;
3
+ }
4
+
5
+ export { areRuleModesEqual as default };
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ function areRuleQueriesEqual(aRule, bRule) {
4
+ const aQueryTypes = Object.keys(aRule.at);
5
+ const bQueryTypes = Object.keys(bRule.at);
6
+ if (aQueryTypes.length !== bQueryTypes.length) {
7
+ return false;
8
+ }
9
+ for (const aQueryType of aQueryTypes){
10
+ const aAtComponents = aRule.at[aQueryType];
11
+ const bAtComponents = bRule.at[aQueryType];
12
+ for (const aAtComponent of aAtComponents){
13
+ const aAtComponentToken = aRule.resolveAtComponent(aAtComponent);
14
+ if (!bAtComponents.find((bAtComponent)=>bRule.resolveAtComponent(bAtComponent) === aAtComponentToken)) {
15
+ return false;
16
+ }
17
+ }
18
+ }
19
+ return true;
20
+ }
21
+
22
+ module.exports = areRuleQueriesEqual;
@@ -0,0 +1,2 @@
1
+ import type { Rule } from '../rule';
2
+ export default function areRuleQueriesEqual(aRule: Rule, bRule: Rule): boolean;
@@ -0,0 +1,20 @@
1
+ function areRuleQueriesEqual(aRule, bRule) {
2
+ const aQueryTypes = Object.keys(aRule.at);
3
+ const bQueryTypes = Object.keys(bRule.at);
4
+ if (aQueryTypes.length !== bQueryTypes.length) {
5
+ return false;
6
+ }
7
+ for (const aQueryType of aQueryTypes){
8
+ const aAtComponents = aRule.at[aQueryType];
9
+ const bAtComponents = bRule.at[aQueryType];
10
+ for (const aAtComponent of aAtComponents){
11
+ const aAtComponentToken = aRule.resolveAtComponent(aAtComponent);
12
+ if (!bAtComponents.find((bAtComponent)=>bRule.resolveAtComponent(bAtComponent) === aAtComponentToken)) {
13
+ return false;
14
+ }
15
+ }
16
+ }
17
+ return true;
18
+ }
19
+
20
+ export { areRuleQueriesEqual as default };
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ function areRuleSelectorsEqual(aRule, bRule) {
4
+ // suffix
5
+ const aVendorSuffixSelectorKeys = Object.keys(aRule.vendorSuffixSelectors);
6
+ const bVendorSuffixSelectorKeys = Object.keys(bRule.vendorSuffixSelectors);
7
+ if (aVendorSuffixSelectorKeys.length !== bVendorSuffixSelectorKeys.length) return false;
8
+ const isSameVendorSuffixSelectors = aVendorSuffixSelectorKeys.every((eachAKey)=>{
9
+ if (!Object.prototype.hasOwnProperty.call(bRule.vendorSuffixSelectors, eachAKey)) return false;
10
+ const aValues = aRule.vendorSuffixSelectors[eachAKey];
11
+ const bValues = bRule.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 = Object.keys(aRule.vendorPrefixSelectors);
17
+ const bVendorPrefixSelectorKeys = Object.keys(bRule.vendorPrefixSelectors);
18
+ if (aVendorPrefixSelectorKeys.length !== bVendorPrefixSelectorKeys.length) return false;
19
+ const isSameVendorPrefixSelectors = aVendorPrefixSelectorKeys.every((eachAKey)=>{
20
+ if (!Object.prototype.hasOwnProperty.call(bRule.vendorPrefixSelectors, eachAKey)) return false;
21
+ const aValues = aRule.vendorPrefixSelectors[eachAKey];
22
+ const bValues = bRule.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;
@@ -0,0 +1,2 @@
1
+ import type { Rule } from '../rule';
2
+ export default function areRuleSelectorsEqual(aRule: Rule, bRule: Rule): boolean;
@@ -0,0 +1,27 @@
1
+ function areRuleSelectorsEqual(aRule, bRule) {
2
+ // suffix
3
+ const aVendorSuffixSelectorKeys = Object.keys(aRule.vendorSuffixSelectors);
4
+ const bVendorSuffixSelectorKeys = Object.keys(bRule.vendorSuffixSelectors);
5
+ if (aVendorSuffixSelectorKeys.length !== bVendorSuffixSelectorKeys.length) return false;
6
+ const isSameVendorSuffixSelectors = aVendorSuffixSelectorKeys.every((eachAKey)=>{
7
+ if (!Object.prototype.hasOwnProperty.call(bRule.vendorSuffixSelectors, eachAKey)) return false;
8
+ const aValues = aRule.vendorSuffixSelectors[eachAKey];
9
+ const bValues = bRule.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 = Object.keys(aRule.vendorPrefixSelectors);
15
+ const bVendorPrefixSelectorKeys = Object.keys(bRule.vendorPrefixSelectors);
16
+ if (aVendorPrefixSelectorKeys.length !== bVendorPrefixSelectorKeys.length) return false;
17
+ const isSameVendorPrefixSelectors = aVendorPrefixSelectorKeys.every((eachAKey)=>{
18
+ if (!Object.prototype.hasOwnProperty.call(bRule.vendorPrefixSelectors, eachAKey)) return false;
19
+ const aValues = aRule.vendorPrefixSelectors[eachAKey];
20
+ const bValues = bRule.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 };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ var areRuleSelectorsEqual = require('./are-rule-selectors-equal.cjs');
4
+ var areRuleModesEqual = require('./are-rule-modes-equal.cjs');
5
+ var areRuleQueriesEqual = require('./are-rule-queries-equal.cjs');
6
+
7
+ function areRuleStatesEqual(aRule, bRule) {
8
+ return areRuleSelectorsEqual(aRule, bRule) && areRuleModesEqual(aRule, bRule) && areRuleQueriesEqual(aRule, bRule);
9
+ }
10
+
11
+ module.exports = areRuleStatesEqual;
@@ -0,0 +1,2 @@
1
+ import type { Rule } from '../rule';
2
+ export default function areRuleStatesEqual(aRule: Rule, bRule: Rule): boolean;
@@ -0,0 +1,9 @@
1
+ import areRuleSelectorsEqual from './are-rule-selectors-equal.mjs';
2
+ import areRuleModesEqual from './are-rule-modes-equal.mjs';
3
+ import areRuleQueriesEqual from './are-rule-queries-equal.mjs';
4
+
5
+ function areRuleStatesEqual(aRule, bRule) {
6
+ return areRuleSelectorsEqual(aRule, bRule) && areRuleModesEqual(aRule, bRule) && areRuleQueriesEqual(aRule, bRule);
7
+ }
8
+
9
+ export { areRuleStatesEqual as default };
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ function areRulesDuplicated(aRule, bRule) {
4
+ const aKeys = Object.keys(aRule.declarations || {});
5
+ const bKeys = Object.keys(bRule.declarations || {});
6
+ if (aKeys.length !== bKeys.length) {
7
+ return false;
8
+ }
9
+ for (const key of aKeys){
10
+ if (!Object.prototype.hasOwnProperty.call(bRule.declarations, key)) {
11
+ return false;
12
+ }
13
+ }
14
+ return true;
15
+ }
16
+
17
+ module.exports = areRulesDuplicated;
@@ -0,0 +1,2 @@
1
+ import type { Rule } from '../rule';
2
+ export default function areRulesDuplicated(aRule: Rule, bRule: Rule): boolean;
@@ -0,0 +1,15 @@
1
+ function areRulesDuplicated(aRule, bRule) {
2
+ const aKeys = Object.keys(aRule.declarations || {});
3
+ const bKeys = Object.keys(bRule.declarations || {});
4
+ if (aKeys.length !== bKeys.length) {
5
+ return false;
6
+ }
7
+ for (const key of aKeys){
8
+ if (!Object.prototype.hasOwnProperty.call(bRule.declarations, key)) {
9
+ return false;
10
+ }
11
+ }
12
+ return true;
13
+ }
14
+
15
+ export { areRulesDuplicated as default };
@@ -19,18 +19,12 @@ function extendConfig(...configs) {
19
19
  };
20
20
  if (clonedConfig.styles) {
21
21
  formatDeeply(clonedConfig.styles);
22
- } else {
23
- clonedConfig.styles = {};
24
22
  }
25
- if (clonedConfig.mediaQueries) {
26
- formatDeeply(clonedConfig.mediaQueries);
27
- } else {
28
- clonedConfig.mediaQueries = {};
23
+ if (clonedConfig.queries) {
24
+ formatDeeply(clonedConfig.queries);
29
25
  }
30
26
  if (clonedConfig.variables) {
31
27
  formatDeeply(clonedConfig.variables);
32
- } else {
33
- clonedConfig.variables = {};
34
28
  }
35
29
  return clonedConfig;
36
30
  };
@@ -45,15 +39,34 @@ function extendConfig(...configs) {
45
39
  formattedConfigs.push(formatConfig(config));
46
40
  })(eachConfig);
47
41
  }
48
- let extendedConfig = formattedConfigs[0];
49
- for(let i = 1; i < formattedConfigs.length; i++){
42
+ let extendedConfig = {
43
+ animations: {},
44
+ styles: {},
45
+ queries: {},
46
+ variables: {}
47
+ };
48
+ for(let i = 0; i < formattedConfigs.length; i++){
50
49
  const currentFormattedConfig = formattedConfigs[i];
51
- extendedConfig = extend(extendedConfig, currentFormattedConfig);
52
- if (Object.prototype.hasOwnProperty.call(currentFormattedConfig, 'animations') && extendedConfig.animations) {
53
- Object.assign(extendedConfig.animations, currentFormattedConfig.animations);
50
+ for(const key in currentFormattedConfig){
51
+ switch(key){
52
+ case 'animations':
53
+ if (currentFormattedConfig.animations) {
54
+ Object.assign(extendedConfig.animations, currentFormattedConfig.animations);
55
+ }
56
+ break;
57
+ default:
58
+ if (currentFormattedConfig[key]) {
59
+ extendedConfig = extend(extendedConfig, {
60
+ [key]: currentFormattedConfig[key]
61
+ });
62
+ }
63
+ }
64
+ // if (Object.prototype.hasOwnProperty.call(currentFormattedConfig.styles, key)) {
65
+ // Object.assign(extendedConfig.styles[key], currentFormattedConfig.styles[key])
66
+ // }
54
67
  }
55
68
  }
56
69
  return extendedConfig;
57
70
  }
58
71
 
59
- exports.extendConfig = extendConfig;
72
+ module.exports = extendConfig;
@@ -0,0 +1,2 @@
1
+ import type { Config } from '../config';
2
+ export default function extendConfig(...configs: Config[]): Config;