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

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 (200) hide show
  1. package/README.md +6 -8
  2. package/dist/index.d.ts +2 -40
  3. package/dist/index.mjs +1 -42
  4. package/package.json +1 -1
  5. package/src/base.css +1 -0
  6. package/src/index.css +1 -0
  7. package/src/theme.css +1 -0
  8. package/src/utilities.css +1 -0
  9. package/src/variants.css +1 -0
  10. package/dist/_virtual/_commonjsHelpers.cjs +0 -10
  11. package/dist/_virtual/_commonjsHelpers.mjs +0 -7
  12. package/dist/_virtual/css-escape.cjs +0 -5
  13. package/dist/_virtual/css-escape.mjs +0 -3
  14. package/dist/animation-rule.cjs +0 -24
  15. package/dist/animation-rule.d.ts +0 -11
  16. package/dist/animation-rule.mjs +0 -22
  17. package/dist/bin/index.cjs +0 -11
  18. package/dist/bin/index.d.ts +0 -1
  19. package/dist/bin/index.mjs +0 -9
  20. package/dist/common.cjs +0 -208
  21. package/dist/common.d.ts +0 -40
  22. package/dist/common.mjs +0 -180
  23. package/dist/config/animations.cjs +0 -113
  24. package/dist/config/animations.d.ts +0 -110
  25. package/dist/config/animations.mjs +0 -111
  26. package/dist/config/at.cjs +0 -19
  27. package/dist/config/at.d.ts +0 -16
  28. package/dist/config/at.mjs +0 -17
  29. package/dist/config/functions.cjs +0 -141
  30. package/dist/config/functions.d.ts +0 -138
  31. package/dist/config/functions.mjs +0 -139
  32. package/dist/config/index.cjs +0 -40
  33. package/dist/config/index.d.ts +0 -12
  34. package/dist/config/index.mjs +0 -29
  35. package/dist/config/modes.cjs +0 -312
  36. package/dist/config/modes.d.ts +0 -309
  37. package/dist/config/modes.mjs +0 -310
  38. package/dist/config/rules.cjs +0 -2277
  39. package/dist/config/rules.d.ts +0 -1485
  40. package/dist/config/rules.mjs +0 -2275
  41. package/dist/config/screens.cjs +0 -17
  42. package/dist/config/screens.d.ts +0 -14
  43. package/dist/config/screens.mjs +0 -15
  44. package/dist/config/selectors.cjs +0 -25
  45. package/dist/config/selectors.d.ts +0 -22
  46. package/dist/config/selectors.mjs +0 -23
  47. package/dist/config/utilities.cjs +0 -446
  48. package/dist/config/utilities.d.ts +0 -443
  49. package/dist/config/utilities.mjs +0 -444
  50. package/dist/config/variables.cjs +0 -99
  51. package/dist/config/variables.d.ts +0 -423
  52. package/dist/config/variables.mjs +0 -97
  53. package/dist/core.cjs +0 -674
  54. package/dist/core.d.ts +0 -128
  55. package/dist/core.mjs +0 -672
  56. package/dist/create.cjs +0 -10
  57. package/dist/create.d.ts +0 -3
  58. package/dist/create.mjs +0 -8
  59. package/dist/declarers/core.group.cjs +0 -99
  60. package/dist/declarers/core.group.d.ts +0 -2
  61. package/dist/declarers/core.group.mjs +0 -97
  62. package/dist/declarers/core.variable.cjs +0 -9
  63. package/dist/declarers/core.variable.d.ts +0 -4
  64. package/dist/declarers/core.variable.mjs +0 -7
  65. package/dist/declarers/index.cjs +0 -13
  66. package/dist/declarers/index.d.ts +0 -10
  67. package/dist/declarers/index.mjs +0 -11
  68. package/dist/declarers/pair.cjs +0 -12
  69. package/dist/declarers/pair.d.ts +0 -4
  70. package/dist/declarers/pair.mjs +0 -10
  71. package/dist/factories/with-syntax-layer.cjs +0 -83
  72. package/dist/factories/with-syntax-layer.d.ts +0 -26
  73. package/dist/factories/with-syntax-layer.mjs +0 -81
  74. package/dist/function-transformers/core.calc.cjs +0 -225
  75. package/dist/function-transformers/core.calc.d.ts +0 -2
  76. package/dist/function-transformers/core.calc.mjs +0 -223
  77. package/dist/function-transformers/core.variable.cjs +0 -23
  78. package/dist/function-transformers/core.variable.d.ts +0 -7
  79. package/dist/function-transformers/core.variable.mjs +0 -21
  80. package/dist/function-transformers/index.cjs +0 -11
  81. package/dist/function-transformers/index.d.ts +0 -8
  82. package/dist/function-transformers/index.mjs +0 -9
  83. package/dist/index.cjs +0 -118
  84. package/dist/layer.cjs +0 -52
  85. package/dist/layer.d.ts +0 -16
  86. package/dist/layer.mjs +0 -50
  87. package/dist/non-layer.cjs +0 -55
  88. package/dist/non-layer.d.ts +0 -12
  89. package/dist/non-layer.mjs +0 -53
  90. package/dist/polyfills/css-escape.cjs +0 -9
  91. package/dist/polyfills/css-escape.d.ts +0 -0
  92. package/dist/polyfills/css-escape.mjs +0 -7
  93. package/dist/polyfills/css-escape2.cjs +0 -76
  94. package/dist/polyfills/css-escape2.mjs +0 -74
  95. package/dist/register-global.cjs +0 -7
  96. package/dist/register-global.d.ts +0 -5
  97. package/dist/register-global.mjs +0 -5
  98. package/dist/rule.cjs +0 -16
  99. package/dist/rule.d.ts +0 -7
  100. package/dist/rule.mjs +0 -14
  101. package/dist/shared/utils/css-escape.cjs +0 -56
  102. package/dist/shared/utils/css-escape.mjs +0 -54
  103. package/dist/shared/utils/find-native-css-rule-index.cjs +0 -12
  104. package/dist/shared/utils/find-native-css-rule-index.mjs +0 -10
  105. package/dist/syntax-layer.cjs +0 -8
  106. package/dist/syntax-layer.d.ts +0 -18
  107. package/dist/syntax-layer.mjs +0 -6
  108. package/dist/syntax-rule-type.cjs +0 -27
  109. package/dist/syntax-rule-type.d.ts +0 -28
  110. package/dist/syntax-rule-type.mjs +0 -25
  111. package/dist/syntax-rule.cjs +0 -506
  112. package/dist/syntax-rule.d.ts +0 -44
  113. package/dist/syntax-rule.mjs +0 -504
  114. package/dist/transformers/auto-fill-solid.cjs +0 -31
  115. package/dist/transformers/auto-fill-solid.d.ts +0 -2
  116. package/dist/transformers/auto-fill-solid.mjs +0 -29
  117. package/dist/transformers/index.cjs +0 -9
  118. package/dist/transformers/index.d.ts +0 -6
  119. package/dist/transformers/index.mjs +0 -7
  120. package/dist/types/common.cjs +0 -2
  121. package/dist/types/common.d.ts +0 -1
  122. package/dist/types/common.mjs +0 -1
  123. package/dist/types/config.cjs +0 -2
  124. package/dist/types/config.d.ts +0 -79
  125. package/dist/types/config.mjs +0 -1
  126. package/dist/types/syntax.cjs +0 -2
  127. package/dist/types/syntax.d.ts +0 -89
  128. package/dist/types/syntax.mjs +0 -1
  129. package/dist/utils/compare-rule-priority.cjs +0 -143
  130. package/dist/utils/compare-rule-priority.d.ts +0 -7
  131. package/dist/utils/compare-rule-priority.mjs +0 -138
  132. package/dist/utils/equal-at-rules.cjs +0 -22
  133. package/dist/utils/equal-at-rules.d.ts +0 -2
  134. package/dist/utils/equal-at-rules.mjs +0 -20
  135. package/dist/utils/equal-declarations.cjs +0 -10
  136. package/dist/utils/equal-declarations.d.ts +0 -2
  137. package/dist/utils/equal-declarations.mjs +0 -8
  138. package/dist/utils/equal-selectors.cjs +0 -69
  139. package/dist/utils/equal-selectors.d.ts +0 -2
  140. package/dist/utils/equal-selectors.mjs +0 -67
  141. package/dist/utils/equal-variants.cjs +0 -10
  142. package/dist/utils/equal-variants.d.ts +0 -2
  143. package/dist/utils/equal-variants.mjs +0 -8
  144. package/dist/utils/extend-config.cjs +0 -97
  145. package/dist/utils/extend-config.d.ts +0 -11
  146. package/dist/utils/extend-config.mjs +0 -95
  147. package/dist/utils/flatten-meta-object.cjs +0 -38
  148. package/dist/utils/flatten-meta-object.d.ts +0 -13
  149. package/dist/utils/flatten-meta-object.mjs +0 -36
  150. package/dist/utils/flatten-object.cjs +0 -19
  151. package/dist/utils/flatten-object.d.ts +0 -1
  152. package/dist/utils/flatten-object.mjs +0 -17
  153. package/dist/utils/generate-at.cjs +0 -30
  154. package/dist/utils/generate-at.d.ts +0 -2
  155. package/dist/utils/generate-at.mjs +0 -28
  156. package/dist/utils/generate-css.cjs +0 -13
  157. package/dist/utils/generate-css.d.ts +0 -1
  158. package/dist/utils/generate-css.mjs +0 -11
  159. package/dist/utils/generate-selector.cjs +0 -50
  160. package/dist/utils/generate-selector.d.ts +0 -2
  161. package/dist/utils/generate-selector.mjs +0 -48
  162. package/dist/utils/get-single-at-number-rule-node.cjs +0 -9
  163. package/dist/utils/get-single-at-number-rule-node.d.ts +0 -2
  164. package/dist/utils/get-single-at-number-rule-node.mjs +0 -7
  165. package/dist/utils/hex-to-rgb.cjs +0 -30
  166. package/dist/utils/hex-to-rgb.d.ts +0 -1
  167. package/dist/utils/hex-to-rgb.mjs +0 -28
  168. package/dist/utils/is-core-rule.cjs +0 -9
  169. package/dist/utils/is-core-rule.d.ts +0 -1
  170. package/dist/utils/is-core-rule.mjs +0 -7
  171. package/dist/utils/minify-extended-config.cjs +0 -64
  172. package/dist/utils/minify-extended-config.d.ts +0 -9
  173. package/dist/utils/minify-extended-config.mjs +0 -62
  174. package/dist/utils/nest-meta-object.cjs +0 -25
  175. package/dist/utils/nest-meta-object.d.ts +0 -7
  176. package/dist/utils/nest-meta-object.mjs +0 -23
  177. package/dist/utils/parse-at.cjs +0 -156
  178. package/dist/utils/parse-at.d.ts +0 -39
  179. package/dist/utils/parse-at.mjs +0 -154
  180. package/dist/utils/parse-pair.cjs +0 -48
  181. package/dist/utils/parse-pair.d.ts +0 -8
  182. package/dist/utils/parse-pair.mjs +0 -46
  183. package/dist/utils/parse-selector.cjs +0 -114
  184. package/dist/utils/parse-selector.d.ts +0 -19
  185. package/dist/utils/parse-selector.mjs +0 -112
  186. package/dist/utils/parse-value.cjs +0 -39
  187. package/dist/utils/parse-value.d.ts +0 -2
  188. package/dist/utils/parse-value.mjs +0 -37
  189. package/dist/utils/replace-char-outside-quotes.cjs +0 -21
  190. package/dist/utils/replace-char-outside-quotes.d.ts +0 -1
  191. package/dist/utils/replace-char-outside-quotes.mjs +0 -19
  192. package/dist/utils/sort-readable-classes.cjs +0 -86
  193. package/dist/utils/sort-readable-classes.d.ts +0 -7
  194. package/dist/utils/sort-readable-classes.mjs +0 -84
  195. package/dist/utils/split-char-outside-quotes.cjs +0 -29
  196. package/dist/utils/split-char-outside-quotes.d.ts +0 -1
  197. package/dist/utils/split-char-outside-quotes.mjs +0 -27
  198. package/dist/variable-rule.cjs +0 -92
  199. package/dist/variable-rule.d.ts +0 -33
  200. package/dist/variable-rule.mjs +0 -87
@@ -1,27 +0,0 @@
1
- 'use strict';
2
-
3
- var SyntaxRuleType = /*#__PURE__*/ function(SyntaxRuleType) {
4
- /**
5
- * utility classes
6
- * @example block, inline
7
- */ SyntaxRuleType[SyntaxRuleType["Utility"] = -4] = "Utility";
8
- /**
9
- * native shorthand
10
- * @example border, padding, margin
11
- */ SyntaxRuleType[SyntaxRuleType["NativeShorthand"] = -3] = "NativeShorthand";
12
- /**
13
- * shorthand
14
- * @example px, py, mx, my
15
- */ SyntaxRuleType[SyntaxRuleType["Shorthand"] = -2] = "Shorthand";
16
- /**
17
- * native properties
18
- * @example color, background-color, font-size
19
- */ SyntaxRuleType[SyntaxRuleType["Native"] = -1] = "Native";
20
- /**
21
- * normal
22
- * @example grid-cols
23
- */ SyntaxRuleType[SyntaxRuleType["Normal"] = 0] = "Normal";
24
- return SyntaxRuleType;
25
- }(SyntaxRuleType || {});
26
-
27
- module.exports = SyntaxRuleType;
@@ -1,28 +0,0 @@
1
- declare enum SyntaxRuleType {
2
- /**
3
- * utility classes
4
- * @example block, inline
5
- */
6
- Utility = -4,
7
- /**
8
- * native shorthand
9
- * @example border, padding, margin
10
- */
11
- NativeShorthand = -3,
12
- /**
13
- * shorthand
14
- * @example px, py, mx, my
15
- */
16
- Shorthand = -2,
17
- /**
18
- * native properties
19
- * @example color, background-color, font-size
20
- */
21
- Native = -1,
22
- /**
23
- * normal
24
- * @example grid-cols
25
- */
26
- Normal = 0
27
- }
28
- export default SyntaxRuleType;
@@ -1,25 +0,0 @@
1
- var SyntaxRuleType = /*#__PURE__*/ function(SyntaxRuleType) {
2
- /**
3
- * utility classes
4
- * @example block, inline
5
- */ SyntaxRuleType[SyntaxRuleType["Utility"] = -4] = "Utility";
6
- /**
7
- * native shorthand
8
- * @example border, padding, margin
9
- */ SyntaxRuleType[SyntaxRuleType["NativeShorthand"] = -3] = "NativeShorthand";
10
- /**
11
- * shorthand
12
- * @example px, py, mx, my
13
- */ SyntaxRuleType[SyntaxRuleType["Shorthand"] = -2] = "Shorthand";
14
- /**
15
- * native properties
16
- * @example color, background-color, font-size
17
- */ SyntaxRuleType[SyntaxRuleType["Native"] = -1] = "Native";
18
- /**
19
- * normal
20
- * @example grid-cols
21
- */ SyntaxRuleType[SyntaxRuleType["Normal"] = 0] = "Normal";
22
- return SyntaxRuleType;
23
- }(SyntaxRuleType || {});
24
-
25
- export { SyntaxRuleType as default };
@@ -1,506 +0,0 @@
1
- 'use strict';
2
-
3
- var cssEscape = require('./shared/utils/css-escape.cjs');
4
- var syntaxRuleType = require('./syntax-rule-type.cjs');
5
- var common = require('./common.cjs');
6
- var parseValue = require('./utils/parse-value.cjs');
7
- var parseAt = require('./utils/parse-at.cjs');
8
- var generateAt = require('./utils/generate-at.cjs');
9
- var parseSelector = require('./utils/parse-selector.cjs');
10
- var generateSelector = require('./utils/generate-selector.cjs');
11
- var compareRulePriority = require('./utils/compare-rule-priority.cjs');
12
- var index$1 = require('./declarers/index.cjs');
13
- var index = require('./transformers/index.cjs');
14
- var index$2 = require('./function-transformers/index.cjs');
15
-
16
- class SyntaxRule {
17
- name;
18
- css;
19
- registeredSyntax;
20
- fixedClass;
21
- native;
22
- atRules;
23
- priority;
24
- type = syntaxRuleType.Normal;
25
- declarations;
26
- layer;
27
- valid = true;
28
- animationNames;
29
- variableNames;
30
- constructor(name, css, registeredSyntax, fixedClass, mode){
31
- this.name = name;
32
- this.css = css;
33
- this.registeredSyntax = registeredSyntax;
34
- this.fixedClass = fixedClass;
35
- this.mode = mode;
36
- this.layer = css.generalLayer;
37
- Object.assign(this, registeredSyntax);
38
- const { id, definition } = registeredSyntax;
39
- const { declarer, transformer, type, unit, sign } = definition;
40
- this.type = type;
41
- // 1. value / selectorToken
42
- let stateToken;
43
- if (this.type === syntaxRuleType.Utility) {
44
- stateToken = name.slice(id.length - 1);
45
- } else {
46
- let valueToken;
47
- if (sign && name.startsWith(sign)) {
48
- valueToken = name.slice(1);
49
- } else if (id.endsWith('()')) {
50
- valueToken = name;
51
- } else if (id === 'group') {
52
- valueToken = name;
53
- } else {
54
- const indexOfColon = name.indexOf(':');
55
- this.keyToken = name.slice(0, indexOfColon + 1);
56
- valueToken = name.slice(indexOfColon + 1);
57
- }
58
- this.valueComponents = [];
59
- const parsedValueIndex = this.parseValues(this.valueComponents, 0, valueToken, unit, '', undefined, false, definition.includeAnimations ? Array.from(this.css.animations.keys()) : []);
60
- this.valueToken = valueToken.slice(0, parsedValueIndex);
61
- stateToken = valueToken.slice(parsedValueIndex);
62
- }
63
- // 2. !important
64
- if (stateToken[0] === '!') {
65
- this.important = true;
66
- stateToken = stateToken.slice(1);
67
- }
68
- this.stateToken = stateToken;
69
- // 4. suffix selector
70
- const stateTokens = stateToken.split('@');
71
- const suffixSelector = stateTokens[0];
72
- if (suffixSelector) {
73
- this.selectorNodes = parseSelector(suffixSelector, css);
74
- }
75
- // 5. atTokens
76
- for(let i = 1; i < stateTokens.length; i++){
77
- const atToken = stateTokens[i];
78
- if (css.config.modes?.[atToken]) {
79
- this.mode = atToken;
80
- continue;
81
- }
82
- this.atToken = (this.atToken || '') + '@' + atToken;
83
- const atRule = parseAt(atToken, css);
84
- const targetNodes = this.atRules?.[atRule.id];
85
- if (targetNodes) {
86
- targetNodes.push(...atRule.nodes);
87
- } else {
88
- this.atRules = {
89
- ...this.atRules,
90
- [atRule.id]: atRule.nodes
91
- };
92
- }
93
- }
94
- if (this.mode && css.config.modeTrigger === 'media') {
95
- const atComp = {
96
- name: 'prefers-color-scheme',
97
- value: this.mode
98
- };
99
- if (this.atRules?.media) {
100
- this.atRules.media.push(atComp);
101
- } else {
102
- this.atRules = {
103
- media: [
104
- atComp
105
- ]
106
- };
107
- }
108
- }
109
- if (this.fixedClass) {
110
- this.layer = css.componentsLayer;
111
- } else {
112
- const onlyNode = this.atRules?.layer?.length === 1 && this.atRules.layer[0];
113
- if (onlyNode) {
114
- if (onlyNode.value === 'base') {
115
- this.layer = css.baseLayer;
116
- this.atRules.layer = undefined;
117
- } else if (onlyNode.value === 'preset') {
118
- this.layer = css.presetLayer;
119
- this.atRules.layer = undefined;
120
- }
121
- }
122
- }
123
- // 7. value
124
- let newValue;
125
- if (this.valueComponents) {
126
- if (transformer) {
127
- if (typeof transformer === 'string') {
128
- const transform = index[transformer];
129
- this.valueComponents = transform.call(this, this.valueComponents);
130
- } else {
131
- const [name, data] = transformer;
132
- const transform = index[name];
133
- this.valueComponents = transform.call(this, this.valueComponents, data);
134
- }
135
- }
136
- newValue = this.resolveValue(this.valueComponents, unit, [], false);
137
- if (definition.declarations) {
138
- const declarations = {};
139
- if (Array.isArray(definition.declarations)) {
140
- for (const property of definition.declarations){
141
- declarations[property] = newValue;
142
- }
143
- } else {
144
- for(const propertyName in definition.declarations){
145
- const propertyValue = definition.declarations[propertyName];
146
- declarations[propertyName] = propertyValue === undefined ? newValue : Array.isArray(propertyValue) ? propertyValue.map((v)=>v === undefined ? newValue : v).join('') : propertyValue;
147
- }
148
- }
149
- this.declarations = declarations;
150
- } else if (declarer) {
151
- if (typeof declarer === 'string') {
152
- const declare = index$1[declarer];
153
- this.declarations = declare.call(this, newValue, this.valueComponents);
154
- } else {
155
- const [name, data] = declarer;
156
- const declare = index$1[name];
157
- this.declarations = declare.call(this, newValue, this.valueComponents, data);
158
- }
159
- } else if (id) {
160
- this.declarations = {
161
- [id]: newValue
162
- };
163
- }
164
- } else {
165
- this.declarations = definition.declarations;
166
- }
167
- if (!Object.entries(this.declarations ?? {}).length) {
168
- this.valid = false;
169
- } else {
170
- for(const propertyName in this.declarations){
171
- if (this.css.animations && (propertyName === 'animation' || propertyName === 'animation-name')) {
172
- const propertyValue = this.declarations[propertyName];
173
- if (!propertyValue) continue;
174
- const rawValues = propertyValue.split(' ');
175
- for (const rawValue of rawValues){
176
- if (this.css.animations.has(rawValue)) {
177
- if (!this.animationNames) {
178
- this.animationNames = new Set([
179
- rawValue
180
- ]);
181
- } else {
182
- this.animationNames.add(rawValue);
183
- }
184
- continue;
185
- }
186
- }
187
- }
188
- }
189
- this.priority = compareRulePriority.calcRulePriority(this);
190
- }
191
- }
192
- get text() {
193
- if (!this.valid) return '';
194
- const propertiesText = [];
195
- for(const propertyName in this.declarations){
196
- const propertyValue = this.declarations[propertyName];
197
- const propertyText = propertyName + ':' + String(propertyValue);
198
- propertiesText.push(propertyText + ((this.important || this.css.config.important) && !propertyText.endsWith('!important') ? '!important' : ''));
199
- }
200
- let text = this.selectorText + '{' + propertiesText.join(';') + '}';
201
- if (this.atRules !== undefined) common.AT_IDENTIFIERS.forEach((id)=>{
202
- const nodes = this.atRules?.[id];
203
- if (!nodes) return;
204
- text = generateAt({
205
- id,
206
- nodes
207
- }) + '{' + text + '}';
208
- });
209
- return text;
210
- }
211
- get selectorText() {
212
- let pre = '';
213
- if (this.css.config.scope) {
214
- pre = this.css.config.scope + ' ' + pre;
215
- }
216
- if (this.mode) {
217
- const modeSelector = this.css.getModeSelector(this.mode);
218
- if (modeSelector) {
219
- pre = modeSelector + ' ' + pre;
220
- }
221
- }
222
- const body = pre + '.' + cssEscape(this.fixedClass ?? this.name);
223
- return this.selectorNodes ? generateSelector(this.selectorNodes, body) : body;
224
- }
225
- resolveValue = (valueComponents, unit, bypassVariableNames, bypassParsing)=>{
226
- const { functions } = this.css.config;
227
- let currentValue = '';
228
- for (const eachValueComponent of valueComponents){
229
- switch(eachValueComponent.type){
230
- case 'function':
231
- const functionDefinition = functions && functions[eachValueComponent.name];
232
- const fnTransformer = functionDefinition?.transformer;
233
- if (fnTransformer && !eachValueComponent.bypassTransform) {
234
- const resolvedValue = this.resolveValue(eachValueComponent.children, functionDefinition.unit ?? unit, bypassVariableNames, bypassParsing || eachValueComponent.name === 'calc');
235
- let result;
236
- if (typeof fnTransformer === 'string') {
237
- const fnTransform = index$2[fnTransformer];
238
- result = fnTransform.call(this, resolvedValue, bypassVariableNames);
239
- } else {
240
- const [name, data] = fnTransformer;
241
- const fnTransform = index$2[name];
242
- result = fnTransform.call(this, resolvedValue, bypassVariableNames, data);
243
- }
244
- currentValue += eachValueComponent.token = eachValueComponent.text = typeof result === 'string' ? result : this.resolveValue(result, functionDefinition?.unit ?? unit, bypassVariableNames, bypassParsing);
245
- } else {
246
- currentValue += eachValueComponent.token = eachValueComponent.text = eachValueComponent.name + eachValueComponent.symbol + this.resolveValue(eachValueComponent.children, functionDefinition?.unit ?? unit, bypassVariableNames, bypassParsing) + common.VALUE_DELIMITERS[eachValueComponent.symbol];
247
- }
248
- break;
249
- // todo: 應挪到 parseValues 階段處理才能支援 variables: { x: 'calc(20vw-30px)' } 這種情況,並且解析上可能會比較合理、精簡
250
- case 'variable':
251
- const variable = this.css.variables.get(eachValueComponent.name);
252
- if (variable) {
253
- const handleVariable = (normalHandler, varHandler)=>{
254
- if (variable.modes) {
255
- if (this.mode) {
256
- const themeVariable = variable.modes[this.mode] ?? variable;
257
- if (themeVariable?.value) {
258
- normalHandler(themeVariable);
259
- }
260
- } else {
261
- if (this.variableNames) {
262
- this.variableNames.add(eachValueComponent.name);
263
- } else {
264
- this.variableNames = new Set([
265
- eachValueComponent.name
266
- ]);
267
- }
268
- varHandler();
269
- }
270
- } else {
271
- normalHandler(variable);
272
- }
273
- };
274
- switch(variable.type){
275
- case 'string':
276
- handleVariable((variable)=>{
277
- const valueComponents = [];
278
- this.parseValues(valueComponents, 0, variable.value, unit, '', undefined, bypassParsing, [
279
- ...bypassVariableNames,
280
- eachValueComponent.name
281
- ]);
282
- currentValue += eachValueComponent.text = this.resolveValue(valueComponents, unit, [
283
- ...bypassVariableNames,
284
- eachValueComponent.name
285
- ], bypassParsing);
286
- }, ()=>{
287
- currentValue += eachValueComponent.text = `var(--${eachValueComponent.name})`;
288
- });
289
- break;
290
- case 'number':
291
- handleVariable((variable)=>{
292
- if (bypassParsing) {
293
- currentValue += eachValueComponent.text = String(variable.value);
294
- } else {
295
- const valueComponent = this.parseValue(variable.value, unit);
296
- currentValue += eachValueComponent.text = valueComponent.value + (valueComponent.unit ?? '');
297
- }
298
- }, ()=>{
299
- currentValue += eachValueComponent.text = unit ? `calc(var(--${eachValueComponent.name}) / 16 * 1rem)` : `var(--${eachValueComponent.name})`;
300
- });
301
- break;
302
- case 'color':
303
- let alpha = eachValueComponent.alpha;
304
- handleVariable((variable)=>{
305
- const colorVariable = variable;
306
- alpha = (alpha || 1) * (colorVariable.alpha || 1);
307
- if (alpha < 1) {
308
- currentValue += eachValueComponent.text = `${colorVariable.space}(${colorVariable.value}/${alpha})`;
309
- } else {
310
- currentValue += eachValueComponent.text = `${colorVariable.space}(${colorVariable.value})`;
311
- }
312
- }, ()=>{
313
- if (alpha !== undefined) {
314
- // use color-mix
315
- currentValue += eachValueComponent.text = `color-mix(in oklab,var(--${eachValueComponent.name}) ${Number(alpha) * 100}%,transparent)`;
316
- } else {
317
- currentValue += eachValueComponent.text = `var(--${eachValueComponent.name})`;
318
- }
319
- });
320
- break;
321
- }
322
- } else {
323
- currentValue += eachValueComponent.text = `var(--${eachValueComponent.name}${eachValueComponent.fallback ? ',' + eachValueComponent.fallback : ''})`;
324
- }
325
- break;
326
- case 'separator':
327
- currentValue += eachValueComponent.text ? eachValueComponent.text : eachValueComponent.text = eachValueComponent.value;
328
- break;
329
- case 'number':
330
- currentValue += eachValueComponent.text = eachValueComponent.value + (eachValueComponent.unit || '');
331
- break;
332
- default:
333
- currentValue += eachValueComponent.text = eachValueComponent.value;
334
- break;
335
- }
336
- }
337
- return currentValue;
338
- };
339
- parseValues = (currentValueComponents, i, value, unit, endSymbol, parentFunctionName, bypassParsing = false, bypassVariableNames = [])=>{
340
- const root = parentFunctionName === undefined;
341
- const isVarFunction = !root && (parentFunctionName.endsWith('$') || parentFunctionName.endsWith('var'));
342
- const checkIsString = (value)=>value === '\'' || value === '"';
343
- const isString = checkIsString(endSymbol);
344
- const separators = [
345
- ','
346
- ];
347
- if (this.definition.separators?.length) {
348
- separators.push(...this.definition.separators);
349
- }
350
- let currentValue = '';
351
- const parse = ()=>{
352
- if (currentValue) {
353
- let handled = false;
354
- if (!isVarFunction || currentValueComponents.length) {
355
- const handleVariable = (variableName, alpha)=>{
356
- const globalVariableValue = this.css.variables.get(variableName);
357
- const variable = this.variables?.get(variableName) || globalVariableValue;
358
- if (variable) {
359
- const name = variable.name ?? variableName;
360
- if (!bypassVariableNames.includes(name)) {
361
- handled = true;
362
- const valueComponent = {
363
- type: 'variable',
364
- name,
365
- variable: this.css.variables.get(name),
366
- token: currentValue
367
- };
368
- if (alpha) valueComponent.alpha = Number(alpha);
369
- currentValueComponents.push(valueComponent);
370
- }
371
- }
372
- };
373
- if (/^\$[a-zA-Z0-9-]+(?:\/[^\/]+)?$/.test(currentValue)) {
374
- const [raw, alpha] = currentValue.slice(1).split('/');
375
- handleVariable(raw, alpha);
376
- } else {
377
- handleVariable(currentValue);
378
- if (!handled) {
379
- const [colorName, alpha] = currentValue.split('/');
380
- handleVariable(colorName, alpha);
381
- }
382
- }
383
- }
384
- if (!handled) {
385
- if (!isVarFunction) {
386
- const result = common.BASE_UNIT_REGEX.exec(currentValue);
387
- if (result) {
388
- currentValue = String(+result[1] * (this.css.config.baseUnit ?? 1));
389
- }
390
- }
391
- if (bypassParsing) {
392
- currentValueComponents.push({
393
- type: 'string',
394
- value: currentValue,
395
- token: currentValue
396
- });
397
- } else {
398
- const parsedValue = this.parseValue(currentValue, unit);
399
- currentValueComponents.push({
400
- ...parsedValue,
401
- token: currentValue
402
- });
403
- }
404
- }
405
- currentValue = '';
406
- }
407
- };
408
- for(; i < value.length; i++){
409
- const val = value[i];
410
- if (val === endSymbol) {
411
- if (isString) {
412
- let count = 0;
413
- for(let j = currentValue.length - 1;; j--){
414
- if (currentValue[j] !== '\\') break;
415
- count++;
416
- }
417
- if (count % 2) {
418
- currentValue += val;
419
- continue;
420
- } else {
421
- parse();
422
- }
423
- } else {
424
- parse();
425
- }
426
- return i;
427
- } else if (!isString && val in common.VALUE_DELIMITERS) {
428
- const functionName = currentValue;
429
- const newValueComponent = {
430
- type: 'function',
431
- name: functionName,
432
- symbol: val,
433
- children: [],
434
- token: ''
435
- };
436
- currentValueComponents.push(newValueComponent);
437
- currentValue = '';
438
- const functionDefinition = val === '(' ? this.css.config.functions?.[functionName] : undefined;
439
- i = this.parseValues(newValueComponent.children, ++i, value, functionDefinition?.unit ?? unit, common.VALUE_DELIMITERS[val], functionName || parentFunctionName || '', bypassParsing || functionName === 'calc');
440
- } else if ((val === '|' || val === ' ') && endSymbol !== '}' && (!isString || parentFunctionName === 'path')) {
441
- parse();
442
- currentValueComponents.push({
443
- type: 'separator',
444
- value: ' ',
445
- token: val
446
- });
447
- } else {
448
- if (!isString) {
449
- if (val === '.') {
450
- if (isNaN(+value[i + 1])) {
451
- if (root) break;
452
- } else if (value[i - 1] === '-') {
453
- currentValue += '0';
454
- }
455
- } else if (separators.includes(val)) {
456
- parse();
457
- currentValueComponents.push({
458
- type: 'separator',
459
- value: val,
460
- text: (val === ',' ? '' : ' ') + val + (val === ',' ? '' : ' '),
461
- token: val
462
- });
463
- continue;
464
- } else if (root && (val === '#' && (currentValue || currentValueComponents.length && currentValueComponents[currentValueComponents.length - 1]['type'] !== 'separator') || [
465
- '!',
466
- '*',
467
- '>',
468
- '+',
469
- '~',
470
- ':',
471
- '[',
472
- '@',
473
- '_'
474
- ].includes(val))) {
475
- break;
476
- }
477
- }
478
- currentValue += val;
479
- }
480
- }
481
- parse();
482
- return i;
483
- };
484
- parseValue(token, unit = this.definition.unit) {
485
- const parsed = parseValue(token, unit, this.css.config.rootSize);
486
- // exclude like `aspect:1/2` from being parsed as 50%
487
- if (this.definition.unit && parsed.type === 'string') {
488
- // 1/2 → 50%
489
- if (/^\d+\/\d+$/.test(parsed.value)) {
490
- const [numerator, denominator] = parsed.value.split('/').map(Number);
491
- return {
492
- token,
493
- value: numerator / denominator * 100,
494
- unit: '%',
495
- type: 'number'
496
- };
497
- }
498
- }
499
- return parsed;
500
- }
501
- get key() {
502
- return (this.fixedClass ? this.fixedClass + ' ' : '') + this.name;
503
- }
504
- }
505
-
506
- exports.SyntaxRule = SyntaxRule;
@@ -1,44 +0,0 @@
1
- import MasterCSS from './core';
2
- import SyntaxRuleType from './syntax-rule-type';
3
- import { type PropertiesHyphen } from 'csstype';
4
- import Layer from './layer';
5
- import type { NumberValueComponent, DefinedRule, ValueComponent } from './types/syntax';
6
- import { AtRuleNode } from './utils/parse-at';
7
- import { AtIdentifier } from './types/config';
8
- import { SelectorNode } from './utils/parse-selector';
9
- import { RulePriority } from './utils/compare-rule-priority';
10
- export declare class SyntaxRule {
11
- readonly name: string;
12
- css: MasterCSS;
13
- readonly registeredSyntax: DefinedRule;
14
- fixedClass?: string | undefined;
15
- native?: CSSRule;
16
- readonly atRules?: Partial<Record<AtIdentifier, AtRuleNode[]>>;
17
- readonly priority: RulePriority;
18
- readonly type: SyntaxRuleType;
19
- readonly declarations?: PropertiesHyphen;
20
- readonly layer: Layer;
21
- readonly valid: boolean;
22
- animationNames?: Set<string>;
23
- variableNames?: Set<string>;
24
- constructor(name: string, css: MasterCSS, registeredSyntax: DefinedRule, fixedClass?: string | undefined, mode?: string);
25
- get text(): string;
26
- get selectorText(): string;
27
- resolveValue: (valueComponents: ValueComponent[], unit: string, bypassVariableNames: string[], bypassParsing: boolean) => string;
28
- parseValues: (currentValueComponents: ValueComponent[], i: number, value: string, unit: string, endSymbol: string, parentFunctionName?: string, bypassParsing?: boolean, bypassVariableNames?: string[]) => number;
29
- parseValue(token: string | number, unit?: any): import(".").StringValueComponent | NumberValueComponent;
30
- get key(): string;
31
- }
32
- export interface SyntaxRule extends DefinedRule {
33
- token: string;
34
- selectorNodes?: SelectorNode[];
35
- important: boolean;
36
- direction: string;
37
- mode: string;
38
- unitToken: string;
39
- keyToken: string;
40
- valueToken: string;
41
- stateToken: string;
42
- atToken: string;
43
- valueComponents: ValueComponent[];
44
- }