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