@master/css 2.0.0-rc.68 → 2.0.0-rc.69

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