@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
package/dist/core.cjs DELETED
@@ -1,674 +0,0 @@
1
- 'use strict';
2
-
3
- var syntaxRule = require('./syntax-rule.cjs');
4
- var hexToRgb = require('./utils/hex-to-rgb.cjs');
5
- var extendConfig = require('./utils/extend-config.cjs');
6
- var rule = require('./rule.cjs');
7
- var syntaxRuleType = require('./syntax-rule-type.cjs');
8
- var layer = require('./layer.cjs');
9
- var syntaxLayer = require('./syntax-layer.cjs');
10
- var nonLayer = require('./non-layer.cjs');
11
- var registerGlobal = require('./register-global.cjs');
12
- var parseAt = require('./utils/parse-at.cjs');
13
- var parseValue = require('./utils/parse-value.cjs');
14
- var parseSelector = require('./utils/parse-selector.cjs');
15
-
16
- class MasterCSS {
17
- customConfig;
18
- baseConfig;
19
- definedRules = [];
20
- config;
21
- layerStatementRule = new rule.Rule('layer-statement', '@layer base,theme,preset,components,general;');
22
- rules = [
23
- this.layerStatementRule
24
- ];
25
- classRules = new Map();
26
- animationsNonLayer = new nonLayer(this);
27
- baseLayer = new syntaxLayer('base', this);
28
- themeLayer = new layer('theme', this);
29
- presetLayer = new syntaxLayer('preset', this);
30
- componentsLayer = new syntaxLayer('components', this);
31
- generalLayer = new syntaxLayer('general', this);
32
- components = new Map();
33
- selectors = new Map();
34
- variables = new Map();
35
- modes = [];
36
- atRules = new Map();
37
- animations = new Map();
38
- constructor(customConfig, baseConfig){
39
- this.customConfig = customConfig;
40
- this.baseConfig = baseConfig;
41
- this.resolve(customConfig);
42
- }
43
- get text() {
44
- return this.rules.sort((a, b)=>{
45
- const order = [
46
- 'layer-statement',
47
- 'base',
48
- 'theme',
49
- 'preset',
50
- 'components',
51
- 'general'
52
- ];
53
- const indexA = order.indexOf(a.name) === -1 ? Infinity : order.indexOf(a.name);
54
- const indexB = order.indexOf(b.name) === -1 ? Infinity : order.indexOf(b.name);
55
- return indexA - indexB;
56
- }).map(({ text })=>text).join('');
57
- }
58
- resolve(customConfig) {
59
- if (customConfig) {
60
- this.customConfig = customConfig;
61
- } else {
62
- customConfig = this.customConfig;
63
- }
64
- // @ts-expect-error read-only
65
- this.config = this.baseConfig ? extendConfig(this.baseConfig, customConfig) : extendConfig(customConfig);
66
- this.resolveVariables();
67
- this.resolveAnimations();
68
- this.resolveSelectors();
69
- this.resolveAtRules();
70
- this.resolveRules();
71
- this.resolveComponents();
72
- }
73
- resolveAnimations() {
74
- const { animations } = this.config;
75
- if (animations) {
76
- for(const animationName in animations){
77
- const eachAnimation = {};
78
- this.animations.set(animationName, eachAnimation);
79
- const eachKeyframes = animations[animationName];
80
- for(const eachKeyframeValue in eachKeyframes){
81
- const newValueByPropertyName = eachAnimation[eachKeyframeValue] = {};
82
- const eachKeyframeDeclarations = eachKeyframes[eachKeyframeValue];
83
- for(const propertyName in eachKeyframeDeclarations){
84
- newValueByPropertyName[propertyName] = eachKeyframeDeclarations[propertyName];
85
- }
86
- }
87
- }
88
- }
89
- }
90
- resolveRules() {
91
- const { rules, utilities } = this.config;
92
- function escapeString(str) {
93
- return str.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
94
- }
95
- if (!rules && !utilities) return;
96
- const rulesEntries = [];
97
- // Collect utility rules
98
- if (utilities) {
99
- for(const utilityName in utilities){
100
- const declarations = utilities[utilityName];
101
- rulesEntries.push([
102
- utilityName,
103
- {
104
- declarations,
105
- type: syntaxRuleType.Utility
106
- }
107
- ]);
108
- }
109
- }
110
- // Collect normal rules
111
- if (rules) {
112
- rulesEntries.push(...Object.entries(rules));
113
- }
114
- const rulesEntriesLength = rulesEntries.length;
115
- // Main loop
116
- rulesEntries.sort((a, b)=>{
117
- if (a[1].type !== b[1].type) {
118
- return (b[1].type || 0) - (a[1].type || 0);
119
- }
120
- if (a[1].kind !== b[1].kind) {
121
- if (!a[1].kind) return 1;
122
- if (!b[1].kind) return -1;
123
- const kindOrder = [
124
- 'color',
125
- 'number',
126
- 'image'
127
- ];
128
- const aKindIndex = kindOrder.indexOf(a[1].kind);
129
- const bKindIndex = kindOrder.indexOf(b[1].kind);
130
- if (aKindIndex !== bKindIndex) {
131
- return aKindIndex - bKindIndex;
132
- }
133
- }
134
- return b[0].localeCompare(a[0], undefined, {
135
- numeric: true
136
- });
137
- }).forEach(([id, def], index)=>{
138
- const order = rulesEntriesLength - 1 - index;
139
- const syntax = {
140
- id,
141
- keys: [],
142
- matchers: {},
143
- order,
144
- definition: def
145
- };
146
- def.unit ??= '';
147
- def.separators ??= [
148
- ','
149
- ];
150
- this.definedRules.push(syntax);
151
- let { matcher, type, subkey, aliasGroups, values, kind, sign, key: originalKey, namespaces } = def;
152
- const keys = [];
153
- let key = originalKey;
154
- // Helper: resolve variable groups
155
- const addNamespace = (namespace)=>{
156
- const dashedNamespace = namespace.replace(/\./g, '-');
157
- this.variables.forEach((v)=>{
158
- if (v.namespace === namespace || v.group === namespace) {
159
- let variableKey = v.name;
160
- if (variableKey.startsWith('-' + dashedNamespace) || variableKey.startsWith(dashedNamespace)) {
161
- variableKey = variableKey.slice(dashedNamespace.length + 1);
162
- }
163
- if (syntax.variables) {
164
- syntax.variables.set(variableKey, v);
165
- } else {
166
- syntax.variables = new Map([
167
- [
168
- variableKey,
169
- v
170
- ]
171
- ]);
172
- }
173
- }
174
- });
175
- };
176
- // 1. Auto variable binding
177
- addNamespace(id);
178
- // 2. Rule-defined variable groups
179
- if (namespaces) {
180
- namespaces.forEach(addNamespace);
181
- }
182
- if (id.endsWith('()')) {
183
- if (!key) def.key = key = id;
184
- const fnName = id.slice(0, -2);
185
- matcher = new RegExp(`^${fnName}\\(`);
186
- } else if (type === syntaxRuleType.NativeShorthand || type === syntaxRuleType.Native) {
187
- if (!key) def.key = key = id;
188
- keys.push(id);
189
- }
190
- if (sign) {
191
- syntax.matchers.arbitrary = new RegExp(`^${sign}[^!*>+~:[@_]+\\|`);
192
- } else if (!matcher) {
193
- if (!key && !subkey) {
194
- keys.push(id);
195
- } else {
196
- if (key && !keys.includes(key)) keys.push(key);
197
- if (subkey) keys.push(subkey);
198
- if (type === syntaxRuleType.Shorthand) keys.push(id);
199
- }
200
- // Ambiguous keys and values
201
- if (aliasGroups?.length) {
202
- const keyPattern = aliasGroups.length > 1 ? `(?:${aliasGroups.join('|')})` : aliasGroups[0];
203
- const variableKeys = Array.from(syntax.variables?.keys() || []);
204
- const valuePatterns = values ? values.map((v)=>`${v}(?:\\b|_)`) : [];
205
- switch(kind){
206
- case 'color':
207
- valuePatterns.push(`(?:#|(?:color|color-contrast|color-mix|hwb|lab|lch|oklab|oklch|rgb|rgba|hsl|hsla|light-dark)\\(.*\\)|(?:currentColor|transparent)(?![a-zA-Z0-9-]))`);
208
- break;
209
- case 'number':
210
- valuePatterns.push('(?:[\\d.]|(?:max|min|calc|clamp)\\([^|]*\\))');
211
- break;
212
- case 'image':
213
- valuePatterns.push('(?:url|linear-gradient|radial-gradient|repeating-linear-gradient|repeating-radial-gradient|conic-gradient)\\(.*\\)');
214
- break;
215
- }
216
- if (valuePatterns?.length) {
217
- syntax.matchers.value = new RegExp(`^${keyPattern}:(?:${valuePatterns.join('|')})[^|]*?(?:@|$)`);
218
- }
219
- if (variableKeys.length) {
220
- syntax.matchers.variable = new RegExp(`^${keyPattern}:(?:${variableKeys.join('|')})(?![a-zA-Z0-9-])[^|]*?(?:@|$)`);
221
- }
222
- }
223
- } else {
224
- syntax.matchers.arbitrary = new RegExp(matcher);
225
- }
226
- // Utility rule matcher
227
- if (type === syntaxRuleType.Utility) {
228
- syntax.id = '.' + id;
229
- syntax.matchers.arbitrary = new RegExp('^' + escapeString(id) + '(?=!|\\*|>|\\+|~|:|\\[|@|_|\\.|$)', 'm');
230
- }
231
- // Key matcher
232
- if (keys.length) {
233
- syntax.keys = keys;
234
- syntax.matchers.key = new RegExp(`^${keys.length > 1 ? `(${keys.join('|')})` : keys[0]}:.`);
235
- }
236
- });
237
- }
238
- resolveComponents() {
239
- const { components = {} } = this.config;
240
- const flatNames = Object.keys(components);
241
- const resolve = (name, currentClasses = [])=>{
242
- const compClasses = this.components.get(name);
243
- if (compClasses) {
244
- currentClasses.push(...compClasses);
245
- return;
246
- }
247
- const className = components[name];
248
- if (!className) return;
249
- const classes = className.replace(/(?:\n\s*)+/g, ' ').trim().split(' ');
250
- for (const cls of classes){
251
- if (flatNames.includes(cls)) {
252
- resolve(cls, currentClasses);
253
- } else {
254
- currentClasses.push(cls);
255
- }
256
- }
257
- this.components.set(name, [
258
- ...currentClasses
259
- ]);
260
- };
261
- // First pass: expand class names recursively
262
- for (const name of flatNames){
263
- resolve(name);
264
- }
265
- }
266
- resolveSelectors() {
267
- const { selectors } = this.config;
268
- if (selectors) {
269
- for(const token in selectors){
270
- const value = selectors[token];
271
- const nodes = parseSelector(value, this, false);
272
- this.selectors.set(token, nodes);
273
- }
274
- }
275
- }
276
- resolveAtRules() {
277
- const { at, screens } = this.config;
278
- if (screens) {
279
- for(const key in screens){
280
- const value = screens[key];
281
- const node = this.parseValue(value);
282
- this.atRules.set(key, {
283
- id: 'media',
284
- nodes: [
285
- node
286
- ]
287
- });
288
- }
289
- }
290
- if (at) {
291
- for(const token in at){
292
- const value = at[token];
293
- if (typeof value === 'number') {
294
- const node = this.parseValue(value);
295
- this.atRules.set(token, {
296
- id: 'media',
297
- nodes: [
298
- node
299
- ]
300
- });
301
- } else {
302
- const atRule = parseAt(value, this, false);
303
- this.atRules.set(token, atRule);
304
- }
305
- }
306
- }
307
- }
308
- resolveVariables() {
309
- const { variables, screens, modes } = this.config;
310
- const aliasVariableModeResolvers = new Map();
311
- const resolveVariable = (variable, mode)=>{
312
- const addVariable = (name, newVariable, currentMode)=>{
313
- if (currentMode) {
314
- const foundVariable = this.variables.get(name);
315
- const newModeVariable = {
316
- value: newVariable.value
317
- };
318
- if ('alpha' in newVariable) newModeVariable.alpha = newVariable.alpha;
319
- if ('space' in newVariable) newModeVariable.space = newVariable.space;
320
- if (foundVariable) {
321
- if (newVariable.type && newVariable.type !== foundVariable.type) {
322
- return;
323
- }
324
- if (!foundVariable.modes) foundVariable.modes = {};
325
- foundVariable.modes[currentMode] = newModeVariable;
326
- } else {
327
- const newRootVaraible = {
328
- name: newVariable.name,
329
- key: newVariable.key,
330
- type: newVariable.type,
331
- modes: {
332
- [currentMode]: newModeVariable
333
- }
334
- };
335
- if (newVariable.namespace) newRootVaraible.namespace = newVariable.namespace;
336
- if (newVariable.group) newRootVaraible.group = newVariable.group;
337
- this.variables.set(name, newRootVaraible);
338
- }
339
- } else {
340
- this.variables.set(name, newVariable);
341
- }
342
- };
343
- if (typeof variable.value === 'number') {
344
- addVariable(variable.name, {
345
- ...variable,
346
- type: 'number'
347
- }, mode);
348
- addVariable('-' + variable.name, {
349
- ...variable,
350
- type: 'number',
351
- name: '-' + variable.name,
352
- key: '-' + variable.key,
353
- value: variable.value * -1
354
- }, mode);
355
- } else if (typeof variable.value === 'string') {
356
- const aliasResult = /^\$\((.*?)\)(?: ?\/ ?(.+?))?$|^\$([a-zA-Z0-9-]+)(?: ?\/ ?(.+?))?$/.exec(variable.value);
357
- if (aliasResult) {
358
- const alias = aliasResult[1] ?? aliasResult[3];
359
- const alpha = aliasResult[2] ?? aliasResult[4];
360
- let aliasVariableModeResolver = aliasVariableModeResolvers.get(variable.name);
361
- if (!aliasVariableModeResolver) {
362
- aliasVariableModeResolvers.set(variable.name, aliasVariableModeResolver = {});
363
- }
364
- aliasVariableModeResolver[mode] = ()=>{
365
- delete aliasVariableModeResolver[mode];
366
- if (!alias) return;
367
- const eachAliasModeVariableResolver = aliasVariableModeResolvers.get(alias);
368
- if (eachAliasModeVariableResolver) {
369
- for (const mode of Object.keys(eachAliasModeVariableResolver)){
370
- eachAliasModeVariableResolver[mode]?.();
371
- }
372
- }
373
- const aliasVariable = this.variables.get(alias);
374
- if (aliasVariable) {
375
- let resolvedAlpha;
376
- if (alpha) {
377
- const numberAlpha = Number(alpha) * (aliasVariable.alpha || 1);
378
- if (numberAlpha < 1) resolvedAlpha = numberAlpha;
379
- }
380
- const newVariable = {
381
- ...variable,
382
- type: aliasVariable.type,
383
- value: aliasVariable.value
384
- };
385
- if (aliasVariable.type === 'color') {
386
- if (resolvedAlpha !== undefined) newVariable.alpha = resolvedAlpha;
387
- if (aliasVariable.space) {
388
- newVariable.space = aliasVariable.space;
389
- }
390
- }
391
- addVariable(newVariable.name, newVariable, mode);
392
- if (aliasVariable.modes) {
393
- for(const eachMode in aliasVariable.modes){
394
- const aliasModeVariable = aliasVariable.modes[eachMode];
395
- addVariable(newVariable.name, aliasModeVariable, eachMode);
396
- }
397
- }
398
- }
399
- };
400
- } else {
401
- // 1. HEX
402
- const hexMatch = /^#([a-f0-9]{3,4}|[a-f0-9]{6}|[a-f0-9]{8})$/i.exec(variable.value);
403
- if (hexMatch) {
404
- const [r, g, b, a] = hexToRgb(hexMatch[1]);
405
- const newVariable = {
406
- ...variable,
407
- type: 'color',
408
- value: `${r} ${g} ${b}`,
409
- space: 'rgb'
410
- };
411
- if (a !== undefined && a < 1) {
412
- newVariable.alpha = a;
413
- }
414
- addVariable(newVariable.name, newVariable, mode);
415
- return;
416
- }
417
- // 2. COLOR FUNCTION
418
- const funcMatch = /^(color|color-contrast|color-mix|hwb|lab|lch|oklab|oklch|rgb|hsl|light-dark)\((.+)\)$/i.exec(variable.value);
419
- if (funcMatch) {
420
- let [, space, rawArgs] = funcMatch;
421
- space = space.toLowerCase();
422
- const normalizedArgs = rawArgs.replace(/\s*\/\s*/g, '/').replace(/\s*,\s*/g, ' ').replace(/\s+/g, ' ').trim();
423
- let alpha;
424
- const alphaMatch = /^(.+?)\/([^\s]+)$/.exec(normalizedArgs);
425
- const finalArgs = alphaMatch ? alphaMatch[1].trim() : normalizedArgs;
426
- alpha = alphaMatch ? Number(alphaMatch[2]) : undefined;
427
- const newVariable = {
428
- ...variable,
429
- type: 'color',
430
- value: finalArgs,
431
- space
432
- };
433
- if (alpha !== undefined) {
434
- newVariable.alpha = alpha;
435
- }
436
- addVariable(newVariable.name, newVariable, mode);
437
- return;
438
- }
439
- // 3. Fallback
440
- addVariable(variable.name, {
441
- ...variable,
442
- type: 'string'
443
- }, mode);
444
- }
445
- }
446
- };
447
- if (variables) {
448
- for(const parnetKey in variables){
449
- const variable = variables[parnetKey];
450
- resolveVariable(variable);
451
- }
452
- }
453
- if (modes) {
454
- for(const mode in modes){
455
- const modeVariables = modes[mode];
456
- if (!modeVariables) continue;
457
- for(const key in modeVariables){
458
- const variable = modeVariables[key];
459
- resolveVariable(variable, mode);
460
- }
461
- }
462
- }
463
- // todo: address to the target variable
464
- aliasVariableModeResolvers.forEach((aliasVariableModeResolver)=>{
465
- for (const mode of Object.keys(aliasVariableModeResolver)){
466
- aliasVariableModeResolver[mode]?.();
467
- }
468
- });
469
- if (screens) {
470
- for(const key in screens){
471
- const value = screens[key];
472
- const name = 'screen-' + key;
473
- this.variables.set(name, {
474
- name,
475
- key,
476
- namespace: 'screen',
477
- group: 'screen',
478
- type: 'number',
479
- value
480
- });
481
- this.variables.set('-' + name, {
482
- name: '-' + name,
483
- key: '-' + key,
484
- namespace: 'screen',
485
- group: 'screen',
486
- type: 'number',
487
- value: value * -1
488
- });
489
- }
490
- }
491
- }
492
- parseValue(token, unit = 'rem') {
493
- return parseValue(token, unit, this.config.rootSize);
494
- }
495
- /**
496
- * Match check if Master CSS syntax
497
- * @param className
498
- * @returns css text
499
- */ match(className) {
500
- /**
501
- * 1. variable
502
- * @example fg:primary bg:blue
503
- */ for (const eachSyntax of this.definedRules){
504
- if (eachSyntax.matchers.variable?.test(className)) return eachSyntax;
505
- }
506
- /**
507
- * 2. value (ambiguous.key * ambiguous.values)
508
- * @example bg:current box-content font:12
509
- */ for (const eachSyntax of this.definedRules){
510
- if (eachSyntax.matchers.value?.test(className)) return eachSyntax;
511
- }
512
- /**
513
- * 3. full key
514
- * @example text-align:center color:blue-40
515
- */ for (const eachSyntax of this.definedRules){
516
- if (eachSyntax.matchers.key?.test(className)) return eachSyntax;
517
- }
518
- /**
519
- * 4. arbitrary
520
- * @example custom RegExp, utility
521
- */ for (const eachSyntax of this.definedRules){
522
- if (eachSyntax.matchers.arbitrary?.test(className)) return eachSyntax;
523
- }
524
- }
525
- /**
526
- * Generate syntax rules from class name
527
- * @param className
528
- * @returns SyntaxRule[]
529
- */ generate(className, mode) {
530
- let syntaxRules = [];
531
- const compClasses = this.components.get(className);
532
- if (compClasses) {
533
- compClasses.forEach((cls)=>{
534
- const syntaxRule = this.create(cls, className, mode);
535
- if (syntaxRule && syntaxRule.valid) {
536
- syntaxRules.push(syntaxRule);
537
- } else {
538
- console.error(`Invalid class "${cls}" found in ${className} component.`);
539
- }
540
- });
541
- } else {
542
- const atIndex = className.indexOf('@');
543
- if (atIndex !== -1) {
544
- const name = className.slice(0, atIndex);
545
- const compClasses = this.components.get(name);
546
- if (compClasses) {
547
- const atToken = className.slice(atIndex);
548
- compClasses.forEach((eachSyntax)=>{
549
- const syntaxRule = this.create(eachSyntax + atToken, className, mode);
550
- if (syntaxRule && syntaxRule.valid) {
551
- syntaxRules.push(syntaxRule);
552
- }
553
- });
554
- }
555
- }
556
- const syntaxRule = this.create(className, undefined, mode);
557
- if (syntaxRule && syntaxRule.valid) {
558
- syntaxRules.push(syntaxRule);
559
- }
560
- }
561
- return syntaxRules;
562
- }
563
- /**
564
- * Create syntax rule from given class name
565
- * @param className
566
- * @returns SyntaxRule
567
- */ create(className, fixedClass, mode) {
568
- const syntaxRule$1 = this.generalLayer.rules.find(({ key })=>key === (fixedClass ? fixedClass + ' ' : '') + className);
569
- if (syntaxRule$1) return syntaxRule$1;
570
- const registeredRule = this.match(className);
571
- if (registeredRule) return new syntaxRule.SyntaxRule(className, this, registeredRule, fixedClass, mode);
572
- }
573
- /**
574
- * Create syntax rule from given selector text
575
- * @param selectorText
576
- */ createFromSelectorText(selectorText) {
577
- const selectorTextSplits = selectorText.split(' ');
578
- const stopChars = /[.#\[!\*>+~:,\s]/;
579
- for(let i = 0; i < selectorTextSplits.length; i++){
580
- const eachField = selectorTextSplits[i];
581
- const modeSelector = this.getModeSelector(eachField);
582
- if (i === 0 && eachField === modeSelector || (i === 0 || i === 1) && eachField === this.config.scope) continue;
583
- if (eachField.startsWith('.')) {
584
- const eachFieldName = eachField.slice(1);
585
- let className = '';
586
- let l = 0;
587
- while(l < eachFieldName.length){
588
- const char = eachFieldName[l];
589
- const nextChar = eachFieldName[l + 1];
590
- if (char === '\\' && nextChar) {
591
- className += nextChar;
592
- l += 2;
593
- continue;
594
- }
595
- if (stopChars.test(char)) break;
596
- className += char;
597
- l++;
598
- }
599
- const syntaxRules = this.generate(className);
600
- if (syntaxRules.length) return syntaxRules;
601
- }
602
- }
603
- }
604
- /**
605
- * 根據蒐集到的所有 DOM class 重新 create
606
- */ refresh(customConfig) {
607
- this.reset();
608
- this.resolve(customConfig);
609
- return this;
610
- }
611
- reset() {
612
- // @ts-ignore
613
- this.animations = new Map();
614
- // @ts-ignore
615
- this.variables = new Map();
616
- // @ts-ignore
617
- this.atRules = new Map();
618
- // @ts-ignore
619
- this.selectors = new Map();
620
- // @ts-ignore
621
- this.components = new Map();
622
- // @ts-ignore
623
- this.classRules = new Map();
624
- this.definedRules.length = 0;
625
- this.baseLayer.reset();
626
- this.themeLayer.reset();
627
- this.presetLayer.reset();
628
- this.componentsLayer.reset();
629
- this.generalLayer.reset();
630
- this.animationsNonLayer.reset();
631
- return this;
632
- }
633
- destroy() {
634
- this.reset();
635
- return this;
636
- }
637
- add(...classNames) {
638
- for (const className of classNames){
639
- const rules = this.classRules.get(className);
640
- if (rules) continue;
641
- const newRules = this.generate(className);
642
- if (newRules.length) {
643
- newRules.forEach((eachSyntaxRule)=>eachSyntaxRule.layer.insert(eachSyntaxRule));
644
- this.classRules.set(className, newRules);
645
- }
646
- }
647
- return this;
648
- }
649
- remove(...classNames) {
650
- /**
651
- * class name 從 DOM tree 中被移除,
652
- * 匹配並刪除對應的 rule
653
- */ for (const className of classNames){
654
- const rules = this.classRules.get(className);
655
- if (rules) {
656
- rules.forEach((rule)=>rule.layer.delete(rule.key));
657
- this.classRules.delete(className);
658
- }
659
- }
660
- }
661
- getModeSelector(modeName) {
662
- switch(this.config.modeTrigger){
663
- case 'class':
664
- return '.' + modeName;
665
- case 'host':
666
- return ':host(.' + modeName + ')';
667
- }
668
- }
669
- }
670
- (function(MasterCSS) {
671
- registerGlobal(MasterCSS);
672
- })(MasterCSS);
673
-
674
- module.exports = MasterCSS;