@master/css-engine 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.
- package/README.md +57 -0
- package/dist/animation-rule.d.ts +12 -0
- package/dist/animation-rule.mjs +38 -0
- package/dist/common.d.ts +40 -0
- package/dist/common.mjs +114 -0
- package/dist/compile-manifest.d.ts +54 -0
- package/dist/compile-manifest.mjs +451 -0
- package/dist/compiler.d.ts +32 -0
- package/dist/compiler.mjs +38 -0
- package/dist/core.d.ts +141 -0
- package/dist/core.mjs +848 -0
- package/dist/emitted-globals.d.ts +4 -0
- package/dist/emitted-globals.mjs +1 -0
- package/dist/hydration-manifest.d.ts +4 -0
- package/dist/hydration-manifest.mjs +61 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.mjs +15 -0
- package/dist/key-aliases.d.ts +4 -0
- package/dist/key-aliases.mjs +95 -0
- package/dist/layer.d.ts +17 -0
- package/dist/layer.mjs +78 -0
- package/dist/namespaces.d.ts +5 -0
- package/dist/namespaces.mjs +28 -0
- package/dist/native-value-namespaces.d.ts +9 -0
- package/dist/native-value-namespaces.mjs +346 -0
- package/dist/non-layer.d.ts +12 -0
- package/dist/non-layer.mjs +53 -0
- package/dist/rule.d.ts +7 -0
- package/dist/rule.mjs +14 -0
- package/dist/theme-layer.d.ts +21 -0
- package/dist/theme-layer.mjs +52 -0
- package/dist/utility-layer.d.ts +10 -0
- package/dist/utility-layer.mjs +118 -0
- package/dist/utility.d.ts +102 -0
- package/dist/utility.mjs +1263 -0
- package/dist/utils/collect-animation-names.d.ts +10 -0
- package/dist/utils/collect-animation-names.mjs +61 -0
- package/dist/utils/collect-variable-names.d.ts +3 -0
- package/dist/utils/collect-variable-names.mjs +18 -0
- package/dist/utils/compare-rule-priority.d.ts +14 -0
- package/dist/utils/compare-rule-priority.mjs +136 -0
- package/dist/utils/css-variables.d.ts +12 -0
- package/dist/utils/css-variables.mjs +197 -0
- package/dist/utils/find-native-css-rule-index.d.ts +1 -0
- package/dist/utils/find-native-css-rule-index.mjs +10 -0
- package/dist/utils/generate-at.d.ts +2 -0
- package/dist/utils/generate-at.mjs +32 -0
- package/dist/utils/generate-selector.d.ts +2 -0
- package/dist/utils/generate-selector.mjs +48 -0
- package/dist/utils/natural-compare.d.ts +2 -0
- package/dist/utils/natural-compare.mjs +6 -0
- package/dist/utils/parse-at.d.ts +44 -0
- package/dist/utils/parse-at.mjs +179 -0
- package/dist/utils/parse-pair.d.ts +8 -0
- package/dist/utils/parse-pair.mjs +46 -0
- package/dist/utils/parse-selector.d.ts +19 -0
- package/dist/utils/parse-selector.mjs +124 -0
- package/dist/utils/parse-value.d.ts +2 -0
- package/dist/utils/parse-value.mjs +37 -0
- package/dist/utils/replace-char-outside-quotes.d.ts +1 -0
- package/dist/utils/replace-char-outside-quotes.mjs +19 -0
- package/dist/utils/split-char-outside-quotes.d.ts +1 -0
- package/dist/utils/split-char-outside-quotes.mjs +27 -0
- package/dist/utils/wrap-at-rules.d.ts +1 -0
- package/dist/utils/wrap-at-rules.mjs +10 -0
- package/dist/variable-rule.d.ts +26 -0
- package/dist/variable-rule.mjs +105 -0
- package/package.json +1 -0
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
import { isNativeCSSShorthandProperty } from '@master/css-schema/native-css-shorthand';
|
|
2
|
+
import { flattenMasterCSSManifestVariables } from '@master/css-schema/manifest';
|
|
3
|
+
import UtilityType from '@master/css-schema/utility-type';
|
|
4
|
+
import { MATCH_NAME_BOUNDARY } from './common.mjs';
|
|
5
|
+
import { builtinKeyAliases as keyAliases } from './key-aliases.mjs';
|
|
6
|
+
import { builtinNativeValueNamespaces as nativeValueNamespaces } from './native-value-namespaces.mjs';
|
|
7
|
+
|
|
8
|
+
const DEFAULT_SETTINGS = {
|
|
9
|
+
rootSize: 16,
|
|
10
|
+
baseUnit: 4,
|
|
11
|
+
defaultMode: 'light',
|
|
12
|
+
modeTrigger: 'media',
|
|
13
|
+
modes: [
|
|
14
|
+
'light',
|
|
15
|
+
'dark'
|
|
16
|
+
]
|
|
17
|
+
};
|
|
18
|
+
// Manifests are compiled by object identity. Mutating a manifest after first use is unsupported.
|
|
19
|
+
const compiledManifestCache = new WeakMap();
|
|
20
|
+
function assertMasterCSSManifest(manifest) {
|
|
21
|
+
if (!manifest || manifest.version !== 1) {
|
|
22
|
+
throw new TypeError('Unsupported MasterCSSManifest version. Expected version 1.');
|
|
23
|
+
}
|
|
24
|
+
if (Array.isArray(manifest.variables)) {
|
|
25
|
+
throw new TypeError('Unsupported MasterCSSManifest variables format. Expected namespace-grouped variables.');
|
|
26
|
+
}
|
|
27
|
+
if ('utilityBuckets' in manifest) {
|
|
28
|
+
throw new TypeError('Unsupported MasterCSSManifest utilityBuckets field. Matcher indexes are engine-derived.');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function pushUnique(target, values) {
|
|
32
|
+
for (const value of values){
|
|
33
|
+
if (!target.includes(value)) target.push(value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function deriveUtilityMetadata(utility) {
|
|
37
|
+
const keys = utility.keys ? [
|
|
38
|
+
...utility.keys
|
|
39
|
+
] : [];
|
|
40
|
+
const aliasGroups = utility.aliasGroups ? [
|
|
41
|
+
...utility.aliasGroups
|
|
42
|
+
] : [];
|
|
43
|
+
for (const matcher of utility.matchers){
|
|
44
|
+
if (matcher.type === 'key') {
|
|
45
|
+
pushUnique(keys, matcher.keys);
|
|
46
|
+
} else if (matcher.type === 'variable' || matcher.type === 'value') {
|
|
47
|
+
pushUnique(aliasGroups, matcher.keys);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (keys.length && !utility.keys) utility.keys = keys;
|
|
51
|
+
if (aliasGroups.length && !utility.aliasGroups) utility.aliasGroups = aliasGroups;
|
|
52
|
+
if (!utility.key) utility.key = keys[0] || aliasGroups[0];
|
|
53
|
+
}
|
|
54
|
+
function isPureNativeDeclarationUtilityDefinition(utility) {
|
|
55
|
+
return utility.emit.type === 'property' && utility.id === utility.emit.property && utility.name === utility.emit.property && !utility.variableAliasRefs?.length && !utility.variableAliases?.length && !utility.kind && !utility.atRules?.length;
|
|
56
|
+
}
|
|
57
|
+
function getVariableKeyByNamespace(variableName, namespace) {
|
|
58
|
+
const negative = variableName.startsWith('-');
|
|
59
|
+
const positiveName = negative ? variableName.slice(1) : variableName;
|
|
60
|
+
if (positiveName !== namespace && !positiveName.startsWith(namespace + '-')) return;
|
|
61
|
+
const key = positiveName === namespace ? '' : positiveName.slice(namespace.length + 1);
|
|
62
|
+
return negative ? '-' + key : key;
|
|
63
|
+
}
|
|
64
|
+
function isIndexableMatchName(name) {
|
|
65
|
+
for(let index = 0; index < name.length; index++){
|
|
66
|
+
if (MATCH_NAME_BOUNDARY.has(name[index])) return false;
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
function pushIndexedUtility(index, key, utility) {
|
|
71
|
+
const utilities = index.get(key);
|
|
72
|
+
if (utilities) {
|
|
73
|
+
if (!utilities.includes(utility)) utilities.push(utility);
|
|
74
|
+
} else {
|
|
75
|
+
index.set(key, [
|
|
76
|
+
utility
|
|
77
|
+
]);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function createKeyedMatcherIndex(utilities, matcherType) {
|
|
81
|
+
const index = new Map();
|
|
82
|
+
for (const utility of utilities){
|
|
83
|
+
for (const matcher of utility.matchers){
|
|
84
|
+
if (matcher.type !== matcherType) continue;
|
|
85
|
+
for (const key of matcher.keys){
|
|
86
|
+
pushIndexedUtility(index, key, utility);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return index;
|
|
91
|
+
}
|
|
92
|
+
function createPatternMatcherIndex(utilities) {
|
|
93
|
+
const index = new Map();
|
|
94
|
+
for (const utility of utilities){
|
|
95
|
+
for (const matcher of utility.matchers){
|
|
96
|
+
if (matcher.type !== 'pattern') continue;
|
|
97
|
+
for (const value of matcher.values){
|
|
98
|
+
const name = matcher.prefix + value;
|
|
99
|
+
if (isIndexableMatchName(name)) {
|
|
100
|
+
pushIndexedUtility(index, name, utility);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return index;
|
|
106
|
+
}
|
|
107
|
+
function canIndexPatternUtilities(utilities) {
|
|
108
|
+
return utilities.every((utility)=>utility.matchers.every((matcher)=>matcher.type !== 'pattern' || matcher.values.every((value)=>isIndexableMatchName(matcher.prefix + value))));
|
|
109
|
+
}
|
|
110
|
+
function createStaticMatcherIndex(utilities) {
|
|
111
|
+
const index = new Map();
|
|
112
|
+
for (const utility of utilities){
|
|
113
|
+
for (const matcher of utility.matchers){
|
|
114
|
+
if (matcher.type === 'static' && isIndexableMatchName(matcher.name)) {
|
|
115
|
+
pushIndexedUtility(index, matcher.name, utility);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return index;
|
|
120
|
+
}
|
|
121
|
+
function canIndexStaticOnlyUtilities(utilities) {
|
|
122
|
+
return utilities.every((utility)=>utility.matchers.length && utility.matchers.every((matcher)=>matcher.type === 'static' && isIndexableMatchName(matcher.name)));
|
|
123
|
+
}
|
|
124
|
+
function createCompiledSettings(manifest) {
|
|
125
|
+
return {
|
|
126
|
+
...DEFAULT_SETTINGS,
|
|
127
|
+
...manifest.settings || {},
|
|
128
|
+
modes: manifest.settings?.modes ? [
|
|
129
|
+
...manifest.settings.modes
|
|
130
|
+
] : [
|
|
131
|
+
...DEFAULT_SETTINGS.modes
|
|
132
|
+
]
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function cloneCompiledSettings(settings) {
|
|
136
|
+
return {
|
|
137
|
+
...settings,
|
|
138
|
+
modes: [
|
|
139
|
+
...settings.modes
|
|
140
|
+
]
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function compileKeyAliases() {
|
|
144
|
+
const keyAliases$1 = new Map();
|
|
145
|
+
for (const [key, property] of Object.entries(keyAliases)){
|
|
146
|
+
if (key && property && key !== property) {
|
|
147
|
+
keyAliases$1.set(key, property);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return keyAliases$1;
|
|
151
|
+
}
|
|
152
|
+
function compileVariables(manifest) {
|
|
153
|
+
const variables = new Map();
|
|
154
|
+
for (const definition of flattenMasterCSSManifestVariables(manifest.variables)){
|
|
155
|
+
if (!definition.name || !definition.type || definition.value === false) continue;
|
|
156
|
+
variables.set(definition.name, {
|
|
157
|
+
name: definition.name,
|
|
158
|
+
key: definition.key,
|
|
159
|
+
type: definition.type,
|
|
160
|
+
...definition.namespace ? {
|
|
161
|
+
namespace: definition.namespace
|
|
162
|
+
} : {},
|
|
163
|
+
...definition.value !== undefined ? {
|
|
164
|
+
value: Array.isArray(definition.value) ? definition.value.join(',') : definition.value
|
|
165
|
+
} : {},
|
|
166
|
+
...definition.numeric ? {
|
|
167
|
+
numeric: {
|
|
168
|
+
...definition.numeric
|
|
169
|
+
}
|
|
170
|
+
} : {},
|
|
171
|
+
...definition.modes ? {
|
|
172
|
+
modes: {
|
|
173
|
+
...definition.modes
|
|
174
|
+
}
|
|
175
|
+
} : {},
|
|
176
|
+
...definition.dependencies?.length ? {
|
|
177
|
+
dependencies: new Set(definition.dependencies)
|
|
178
|
+
} : {},
|
|
179
|
+
...definition.inline ? {
|
|
180
|
+
inline: true
|
|
181
|
+
} : {},
|
|
182
|
+
...definition.static ? {
|
|
183
|
+
static: true
|
|
184
|
+
} : {}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return variables;
|
|
188
|
+
}
|
|
189
|
+
function compileAnimations(manifest) {
|
|
190
|
+
const animations = new Map();
|
|
191
|
+
if (!manifest.animations) return animations;
|
|
192
|
+
for(const animationName in manifest.animations){
|
|
193
|
+
const eachAnimation = {};
|
|
194
|
+
animations.set(animationName, eachAnimation);
|
|
195
|
+
const eachKeyframes = manifest.animations[animationName];
|
|
196
|
+
for(const eachKeyframeValue in eachKeyframes){
|
|
197
|
+
const newValueByPropertyName = eachAnimation[eachKeyframeValue] = {};
|
|
198
|
+
const eachKeyframeDeclarations = eachKeyframes[eachKeyframeValue];
|
|
199
|
+
for(const propertyName in eachKeyframeDeclarations){
|
|
200
|
+
newValueByPropertyName[propertyName] = eachKeyframeDeclarations[propertyName];
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return animations;
|
|
205
|
+
}
|
|
206
|
+
function compileAtRuleMap(atRules) {
|
|
207
|
+
const target = new Map();
|
|
208
|
+
if (!atRules) return target;
|
|
209
|
+
for (const [name, atRule] of Object.entries(atRules)){
|
|
210
|
+
target.set(name, {
|
|
211
|
+
id: atRule.id,
|
|
212
|
+
nodes: atRule.nodes
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
return target;
|
|
216
|
+
}
|
|
217
|
+
function compileVariantAliases(manifest) {
|
|
218
|
+
const selectors = new Map();
|
|
219
|
+
if (manifest.selectors) {
|
|
220
|
+
for (const [name, nodes] of Object.entries(manifest.selectors)){
|
|
221
|
+
selectors.set(name, nodes);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const variants = new Map();
|
|
225
|
+
for (const variant of manifest.variants || []){
|
|
226
|
+
variants.set(variant.token, variant.branches.map((branch)=>({
|
|
227
|
+
...branch,
|
|
228
|
+
...branch.selectorNodes?.length ? {
|
|
229
|
+
selectorNodes: branch.selectorNodes
|
|
230
|
+
} : {},
|
|
231
|
+
...branch.atRules?.length ? {
|
|
232
|
+
atRules: [
|
|
233
|
+
...branch.atRules
|
|
234
|
+
]
|
|
235
|
+
} : {},
|
|
236
|
+
...branch.atRuleNodes?.length ? {
|
|
237
|
+
atRuleNodes: branch.atRuleNodes.map((atRule)=>({
|
|
238
|
+
id: atRule.id,
|
|
239
|
+
nodes: atRule.nodes
|
|
240
|
+
}))
|
|
241
|
+
} : {}
|
|
242
|
+
})));
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
selectors,
|
|
246
|
+
variants
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
function createVariableAliasRefResolver(variables) {
|
|
250
|
+
const aliasRefCache = new Map();
|
|
251
|
+
return (ref)=>{
|
|
252
|
+
const cached = aliasRefCache.get(ref);
|
|
253
|
+
if (cached) return cached;
|
|
254
|
+
const namespace = ref[0] === '=' || ref[0] === '~' ? ref.slice(1) : '';
|
|
255
|
+
const aliases = [];
|
|
256
|
+
const usedKeys = new Set();
|
|
257
|
+
if (namespace) {
|
|
258
|
+
for (const variable of variables.values()){
|
|
259
|
+
const key = getVariableKeyByNamespace(variable.name, namespace);
|
|
260
|
+
if (key === undefined || usedKeys.has(key)) continue;
|
|
261
|
+
usedKeys.add(key);
|
|
262
|
+
aliases.push([
|
|
263
|
+
key,
|
|
264
|
+
variable.name
|
|
265
|
+
]);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
aliasRefCache.set(ref, aliases);
|
|
269
|
+
return aliases;
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function compileUtilityDefinition(utility, variables, resolveAliasRef, index = 0, count = 1) {
|
|
273
|
+
const definedUtility = {
|
|
274
|
+
...utility,
|
|
275
|
+
name: utility.name || utility.id,
|
|
276
|
+
order: utility.order ?? count - index - 1,
|
|
277
|
+
layer: utility.layer || 'utilities',
|
|
278
|
+
matchers: utility.matchers.map((matcher)=>({
|
|
279
|
+
...matcher
|
|
280
|
+
}))
|
|
281
|
+
};
|
|
282
|
+
const variableAliases = [
|
|
283
|
+
...utility.variableAliases || [],
|
|
284
|
+
...(utility.variableAliasRefs || []).flatMap(resolveAliasRef)
|
|
285
|
+
];
|
|
286
|
+
if (variableAliases.length) {
|
|
287
|
+
definedUtility.variables = new Map();
|
|
288
|
+
for (const [variableKey, variableName] of variableAliases){
|
|
289
|
+
if (definedUtility.variables.has(variableKey)) continue;
|
|
290
|
+
const variable = variables.get(variableName);
|
|
291
|
+
if (variable) definedUtility.variables.set(variableKey, variable);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
deriveUtilityMetadata(definedUtility);
|
|
295
|
+
return definedUtility;
|
|
296
|
+
}
|
|
297
|
+
function createNativeValueNamespaceUtility(property, namespace) {
|
|
298
|
+
return {
|
|
299
|
+
id: property,
|
|
300
|
+
name: property,
|
|
301
|
+
type: isNativeCSSShorthandProperty(property) ? UtilityType.Shorthand : UtilityType.Normal,
|
|
302
|
+
order: 0,
|
|
303
|
+
variableAliasRefs: [
|
|
304
|
+
...namespace.variableAliasRefs
|
|
305
|
+
],
|
|
306
|
+
emit: {
|
|
307
|
+
type: 'property',
|
|
308
|
+
property
|
|
309
|
+
},
|
|
310
|
+
matchers: [
|
|
311
|
+
{
|
|
312
|
+
type: 'key',
|
|
313
|
+
keys: [
|
|
314
|
+
property
|
|
315
|
+
]
|
|
316
|
+
}
|
|
317
|
+
]
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
function compileNativeValueNamespaces(variables, resolveAliasRef) {
|
|
321
|
+
const nativeValueNamespaceUtilities = new Map();
|
|
322
|
+
for (const namespace of nativeValueNamespaces){
|
|
323
|
+
if (!namespace.properties?.length || !namespace.variableAliasRefs?.length) continue;
|
|
324
|
+
for (const property of namespace.properties){
|
|
325
|
+
if (!property || nativeValueNamespaceUtilities.has(property)) continue;
|
|
326
|
+
const utility = compileUtilityDefinition(createNativeValueNamespaceUtility(property, namespace), variables, resolveAliasRef);
|
|
327
|
+
nativeValueNamespaceUtilities.set(property, utility);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return nativeValueNamespaceUtilities;
|
|
331
|
+
}
|
|
332
|
+
function registerNativeDeclarationFastPathPolicy(target, utility) {
|
|
333
|
+
const isPureNativeDeclaration = isPureNativeDeclarationUtilityDefinition(utility);
|
|
334
|
+
for (const matcher of utility.matchers){
|
|
335
|
+
if (matcher.type !== 'key' && matcher.type !== 'value' && matcher.type !== 'variable') continue;
|
|
336
|
+
for (const key of matcher.keys){
|
|
337
|
+
if (isPureNativeDeclaration && key === utility.emit.property) continue;
|
|
338
|
+
target.add(key);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function pushBucketUtility(target, utility) {
|
|
343
|
+
if (!target.includes(utility)) target.push(utility);
|
|
344
|
+
}
|
|
345
|
+
function registerUtilityMatcherBuckets(utility, buckets) {
|
|
346
|
+
for (const matcher of utility.matchers){
|
|
347
|
+
switch(matcher.type){
|
|
348
|
+
case 'variable':
|
|
349
|
+
if (utility.variableAliases?.length || utility.variableAliasRefs?.length) {
|
|
350
|
+
pushBucketUtility(buckets.variableMatcherUtilities, utility);
|
|
351
|
+
}
|
|
352
|
+
break;
|
|
353
|
+
case 'value':
|
|
354
|
+
if (utility.kind) pushBucketUtility(buckets.valueMatcherUtilities, utility);
|
|
355
|
+
break;
|
|
356
|
+
case 'key':
|
|
357
|
+
pushBucketUtility(buckets.keyMatcherUtilities, utility);
|
|
358
|
+
break;
|
|
359
|
+
case 'pattern':
|
|
360
|
+
pushBucketUtility(buckets.patternMatcherUtilities, utility);
|
|
361
|
+
break;
|
|
362
|
+
default:
|
|
363
|
+
pushBucketUtility(buckets.arbitraryMatcherUtilities, utility);
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
function compileUtilities(manifest, variables, resolveAliasRef) {
|
|
369
|
+
const definedUtilities = [];
|
|
370
|
+
const variableMatcherUtilities = [];
|
|
371
|
+
const valueMatcherUtilities = [];
|
|
372
|
+
const keyMatcherUtilities = [];
|
|
373
|
+
const patternMatcherUtilities = [];
|
|
374
|
+
const arbitraryMatcherUtilities = [];
|
|
375
|
+
const nativeDeclarationFastPathBlockedProperties = new Set();
|
|
376
|
+
const manifestUtilities = manifest.utilities || [];
|
|
377
|
+
for(let index = 0; index < manifestUtilities.length; index++){
|
|
378
|
+
const utility = manifestUtilities[index];
|
|
379
|
+
const definedUtility = compileUtilityDefinition(utility, variables, resolveAliasRef, index, manifestUtilities.length);
|
|
380
|
+
registerNativeDeclarationFastPathPolicy(nativeDeclarationFastPathBlockedProperties, definedUtility);
|
|
381
|
+
definedUtilities.push(definedUtility);
|
|
382
|
+
registerUtilityMatcherBuckets(definedUtility, {
|
|
383
|
+
variableMatcherUtilities,
|
|
384
|
+
valueMatcherUtilities,
|
|
385
|
+
keyMatcherUtilities,
|
|
386
|
+
patternMatcherUtilities,
|
|
387
|
+
arbitraryMatcherUtilities
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
return {
|
|
391
|
+
definedUtilities,
|
|
392
|
+
variableMatcherUtilities,
|
|
393
|
+
valueMatcherUtilities,
|
|
394
|
+
keyMatcherUtilities,
|
|
395
|
+
patternMatcherUtilities,
|
|
396
|
+
arbitraryMatcherUtilities,
|
|
397
|
+
variableMatcherIndex: createKeyedMatcherIndex(variableMatcherUtilities, 'variable'),
|
|
398
|
+
valueMatcherIndex: createKeyedMatcherIndex(valueMatcherUtilities, 'value'),
|
|
399
|
+
keyMatcherIndex: createKeyedMatcherIndex(keyMatcherUtilities, 'key'),
|
|
400
|
+
patternMatcherIndex: canIndexPatternUtilities(patternMatcherUtilities) ? createPatternMatcherIndex(patternMatcherUtilities) : undefined,
|
|
401
|
+
arbitraryStaticMatcherIndex: canIndexStaticOnlyUtilities(arbitraryMatcherUtilities) ? createStaticMatcherIndex(arbitraryMatcherUtilities) : undefined,
|
|
402
|
+
nativeDeclarationFastPathBlockedProperties
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
function compileManifest(manifest) {
|
|
406
|
+
assertMasterCSSManifest(manifest);
|
|
407
|
+
const settings = createCompiledSettings(manifest);
|
|
408
|
+
const variables = compileVariables(manifest);
|
|
409
|
+
const animations = compileAnimations(manifest);
|
|
410
|
+
const { selectors, variants } = compileVariantAliases(manifest);
|
|
411
|
+
const resolveAliasRef = createVariableAliasRefResolver(variables);
|
|
412
|
+
const nativeValueNamespaceUtilities = compileNativeValueNamespaces(variables, resolveAliasRef);
|
|
413
|
+
const utilities = compileUtilities(manifest, variables, resolveAliasRef);
|
|
414
|
+
return {
|
|
415
|
+
manifest,
|
|
416
|
+
settings,
|
|
417
|
+
definedUtilities: utilities.definedUtilities,
|
|
418
|
+
variableMatcherUtilities: utilities.variableMatcherUtilities,
|
|
419
|
+
valueMatcherUtilities: utilities.valueMatcherUtilities,
|
|
420
|
+
keyMatcherUtilities: utilities.keyMatcherUtilities,
|
|
421
|
+
patternMatcherUtilities: utilities.patternMatcherUtilities,
|
|
422
|
+
arbitraryMatcherUtilities: utilities.arbitraryMatcherUtilities,
|
|
423
|
+
variableMatcherIndex: utilities.variableMatcherIndex,
|
|
424
|
+
valueMatcherIndex: utilities.valueMatcherIndex,
|
|
425
|
+
keyMatcherIndex: utilities.keyMatcherIndex,
|
|
426
|
+
patternMatcherIndex: utilities.patternMatcherIndex,
|
|
427
|
+
arbitraryStaticMatcherIndex: utilities.arbitraryStaticMatcherIndex,
|
|
428
|
+
selectors,
|
|
429
|
+
variables,
|
|
430
|
+
modes: [
|
|
431
|
+
...settings.modes
|
|
432
|
+
],
|
|
433
|
+
atRules: compileAtRuleMap(manifest.atRules),
|
|
434
|
+
variants,
|
|
435
|
+
breakpointAtRules: compileAtRuleMap(manifest.breakpointAtRules),
|
|
436
|
+
containerAtRules: compileAtRuleMap(manifest.containerAtRules),
|
|
437
|
+
animations,
|
|
438
|
+
nativeDeclarationFastPathBlockedProperties: utilities.nativeDeclarationFastPathBlockedProperties,
|
|
439
|
+
nativeValueNamespaceUtilities,
|
|
440
|
+
keyAliases: compileKeyAliases()
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
function getCompiledManifest(manifest) {
|
|
444
|
+
const cached = compiledManifestCache.get(manifest);
|
|
445
|
+
if (cached) return cached;
|
|
446
|
+
const compiledManifest = compileManifest(manifest);
|
|
447
|
+
compiledManifestCache.set(manifest, compiledManifest);
|
|
448
|
+
return compiledManifest;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export { cloneCompiledSettings, compileManifest, getCompiledManifest, isPureNativeDeclarationUtilityDefinition };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import MasterCSS from './core';
|
|
2
|
+
import parseAt from './utils/parse-at';
|
|
3
|
+
import generateAt from './utils/generate-at';
|
|
4
|
+
import parseSelector from './utils/parse-selector';
|
|
5
|
+
import generateSelector from './utils/generate-selector';
|
|
6
|
+
import compareRulePriority from './utils/compare-rule-priority';
|
|
7
|
+
import type { Utility } from './utility';
|
|
8
|
+
import type { MasterCSSManifest } from '@master/css-schema/manifest';
|
|
9
|
+
import type { MasterCSSEmittedGlobals } from './emitted-globals';
|
|
10
|
+
import type { MasterCSSOptions } from './core';
|
|
11
|
+
export { MasterCSS, compareRulePriority, generateAt, generateSelector, parseAt, parseSelector };
|
|
12
|
+
export type { Utility as GeneratedRule };
|
|
13
|
+
export type * from '@master/css-schema/manifest';
|
|
14
|
+
export declare function createCompilerCSS(manifest: MasterCSSManifest, emittedGlobals?: MasterCSSEmittedGlobals, options?: MasterCSSOptions): MasterCSS;
|
|
15
|
+
export declare function expandClassName(manifest: MasterCSSManifest, className: string, mode?: string): Utility[];
|
|
16
|
+
export declare function inspectGeneratedRule(rule: Utility): {
|
|
17
|
+
className: string;
|
|
18
|
+
key: string;
|
|
19
|
+
layer: import("@master/css-schema/manifest").MasterCSSManifestUtilityLayerName;
|
|
20
|
+
explicitLayer: import("@master/css-schema/manifest").MasterCSSManifestUtilityLayerName | undefined;
|
|
21
|
+
selector: string;
|
|
22
|
+
declarations: import("csstype").PropertiesHyphen<0 | (string & {}), string & {}> | undefined;
|
|
23
|
+
declarationRules: {
|
|
24
|
+
declarations: import("csstype").PropertiesHyphen;
|
|
25
|
+
atRules?: string[];
|
|
26
|
+
selector?: string;
|
|
27
|
+
}[] | undefined;
|
|
28
|
+
atRules: Partial<Record<import("@master/css-schema/manifest").MasterCSSManifestAtIdentifier, import("./utils/parse-at").AtRuleNode[]>> | undefined;
|
|
29
|
+
priority: import("./utils/compare-rule-priority").RulePriority;
|
|
30
|
+
variableNames: string[];
|
|
31
|
+
animationNames: string[];
|
|
32
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import MasterCSS from './core.mjs';
|
|
2
|
+
export { default as parseAt } from './utils/parse-at.mjs';
|
|
3
|
+
export { default as generateAt } from './utils/generate-at.mjs';
|
|
4
|
+
export { default as parseSelector } from './utils/parse-selector.mjs';
|
|
5
|
+
export { default as generateSelector } from './utils/generate-selector.mjs';
|
|
6
|
+
export { default as compareRulePriority } from './utils/compare-rule-priority.mjs';
|
|
7
|
+
|
|
8
|
+
function createCompilerCSS(manifest, emittedGlobals, options) {
|
|
9
|
+
return MasterCSS.create({
|
|
10
|
+
manifest,
|
|
11
|
+
emittedGlobals,
|
|
12
|
+
...options
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function expandClassName(manifest, className, mode) {
|
|
16
|
+
return createCompilerCSS(manifest).createRules(className, undefined, mode);
|
|
17
|
+
}
|
|
18
|
+
function inspectGeneratedRule(rule) {
|
|
19
|
+
return {
|
|
20
|
+
className: rule.name,
|
|
21
|
+
key: rule.key,
|
|
22
|
+
layer: rule.layerName,
|
|
23
|
+
explicitLayer: rule.explicitLayerName,
|
|
24
|
+
selector: rule.selectorText,
|
|
25
|
+
declarations: rule.declarations,
|
|
26
|
+
declarationRules: rule.declarationRules,
|
|
27
|
+
atRules: rule.atRules,
|
|
28
|
+
priority: rule.priority,
|
|
29
|
+
variableNames: rule.variableNames ? [
|
|
30
|
+
...rule.variableNames
|
|
31
|
+
] : [],
|
|
32
|
+
animationNames: rule.animationNames ? [
|
|
33
|
+
...rule.animationNames
|
|
34
|
+
] : []
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { MasterCSS, createCompilerCSS, expandClassName, inspectGeneratedRule };
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Utility } from './utility';
|
|
2
|
+
import type { Rule } from './rule';
|
|
3
|
+
import Layer from './layer';
|
|
4
|
+
import ThemeLayer from './theme-layer';
|
|
5
|
+
import UtilityLayer from './utility-layer';
|
|
6
|
+
import NonLayer from './non-layer';
|
|
7
|
+
import type { Variable } from '@master/css-schema/css-syntax';
|
|
8
|
+
import type { AtRule } from './utils/parse-at';
|
|
9
|
+
import type { SelectorNode } from './utils/parse-selector';
|
|
10
|
+
import type { MasterCSSEmittedGlobals } from './emitted-globals';
|
|
11
|
+
import type { MasterCSSManifest, MasterCSSManifestUtilityLayerName, MasterCSSManifestVariantBranch, MasterCSSManifestVariantToken } from '@master/css-schema/manifest';
|
|
12
|
+
import { type CompiledUtility, type EngineSettings } from './compile-manifest';
|
|
13
|
+
export type { CompiledUtility } from './compile-manifest';
|
|
14
|
+
export interface NativeCSSDeclaration {
|
|
15
|
+
property: string;
|
|
16
|
+
value: string;
|
|
17
|
+
}
|
|
18
|
+
export type NativeCSSDeclarationMatcher = (declaration: NativeCSSDeclaration) => boolean;
|
|
19
|
+
export interface MasterCSSOptions {
|
|
20
|
+
nativeDeclarationMatcher?: NativeCSSDeclarationMatcher;
|
|
21
|
+
}
|
|
22
|
+
export interface MasterCSSCreateOptions extends MasterCSSOptions {
|
|
23
|
+
manifest: MasterCSSManifest;
|
|
24
|
+
emittedGlobals?: MasterCSSEmittedGlobals;
|
|
25
|
+
}
|
|
26
|
+
export default class MasterCSS {
|
|
27
|
+
protected readonly options: MasterCSSOptions;
|
|
28
|
+
definedUtilities: CompiledUtility[];
|
|
29
|
+
protected variableMatcherUtilities: CompiledUtility[];
|
|
30
|
+
protected valueMatcherUtilities: CompiledUtility[];
|
|
31
|
+
protected keyMatcherUtilities: CompiledUtility[];
|
|
32
|
+
protected patternMatcherUtilities: CompiledUtility[];
|
|
33
|
+
protected arbitraryMatcherUtilities: CompiledUtility[];
|
|
34
|
+
protected variableMatcherIndex: Map<string, CompiledUtility[]>;
|
|
35
|
+
protected valueMatcherIndex: Map<string, CompiledUtility[]>;
|
|
36
|
+
protected keyMatcherIndex: Map<string, CompiledUtility[]>;
|
|
37
|
+
protected patternMatcherIndex?: Map<string, CompiledUtility[]>;
|
|
38
|
+
protected arbitraryStaticMatcherIndex?: Map<string, CompiledUtility[]>;
|
|
39
|
+
settings: EngineSettings;
|
|
40
|
+
readonly rules: (Layer | Rule)[];
|
|
41
|
+
readonly classUtilities: Map<string, Utility[]>;
|
|
42
|
+
readonly animationsNonLayer: NonLayer;
|
|
43
|
+
readonly baseLayer: UtilityLayer;
|
|
44
|
+
readonly themeLayer: ThemeLayer;
|
|
45
|
+
readonly defaultsLayer: UtilityLayer;
|
|
46
|
+
readonly componentsLayer: UtilityLayer;
|
|
47
|
+
readonly utilitiesLayer: UtilityLayer;
|
|
48
|
+
selectors: Map<string, SelectorNode[]>;
|
|
49
|
+
variables: Map<string, Variable>;
|
|
50
|
+
modes: string[];
|
|
51
|
+
atRules: Map<string, AtRule>;
|
|
52
|
+
variants: Map<MasterCSSManifestVariantToken, MasterCSSManifestVariantBranch[]>;
|
|
53
|
+
breakpointAtRules: Map<string, AtRule>;
|
|
54
|
+
containerAtRules: Map<string, AtRule>;
|
|
55
|
+
animations: Map<string, import("@master/css-schema/manifest").MasterCSSManifestKeyframes<import("@master/css-schema/manifest").MasterCSSManifestCSSDeclarations>>;
|
|
56
|
+
protected readonly staticVariableTokens: Set<string>;
|
|
57
|
+
protected readonly staticAnimationTokens: Set<string>;
|
|
58
|
+
readonly emittedGlobals: Required<MasterCSSEmittedGlobals>;
|
|
59
|
+
protected nativeDeclarationFastPathBlockedProperties: Set<string>;
|
|
60
|
+
protected readonly nativeDeclarationMatches: Map<string, boolean>;
|
|
61
|
+
protected readonly nativeDeclarationUtilities: Map<string, CompiledUtility>;
|
|
62
|
+
protected nativeValueNamespaceUtilities: Map<string, CompiledUtility>;
|
|
63
|
+
protected keyAliases: Map<string, string>;
|
|
64
|
+
manifest: MasterCSSManifest;
|
|
65
|
+
static create(options: MasterCSSCreateOptions): MasterCSS;
|
|
66
|
+
protected constructor(manifest: MasterCSSManifest, emittedGlobals?: MasterCSSEmittedGlobals, options?: MasterCSSOptions);
|
|
67
|
+
get text(): string;
|
|
68
|
+
getUtilityLayer(layerName?: MasterCSSManifestUtilityLayerName): UtilityLayer;
|
|
69
|
+
getUtilityLayers(): UtilityLayer[];
|
|
70
|
+
loadManifest(manifest: MasterCSSManifest): void;
|
|
71
|
+
protected applyEmittedGlobalsCounts(emittedGlobals: MasterCSSEmittedGlobals): void;
|
|
72
|
+
registerEmittedGlobals(emittedGlobals?: MasterCSSEmittedGlobals): void;
|
|
73
|
+
isEmittedGlobalsVariable(name: string): boolean;
|
|
74
|
+
isEmittedGlobalsAnimation(name: string): boolean;
|
|
75
|
+
protected insertStaticVariable(name: string, visited?: Set<string>): void;
|
|
76
|
+
protected insertStaticAnimation(name: string): void;
|
|
77
|
+
insertStaticResources(): this;
|
|
78
|
+
resolveVariant(token: MasterCSSManifestVariantToken): MasterCSSManifestVariantBranch[] | undefined;
|
|
79
|
+
parseValue(token: string | number, unit?: string): import("@master/css-schema/css-syntax").StringValueComponent | import("@master/css-schema/css-syntax").NumberValueComponent;
|
|
80
|
+
/**
|
|
81
|
+
* Match check if Master CSS utility
|
|
82
|
+
* @param className
|
|
83
|
+
* @returns css text
|
|
84
|
+
*/
|
|
85
|
+
private matchesMatcher;
|
|
86
|
+
private matchesUtility;
|
|
87
|
+
private matchesExactUtilityDefinition;
|
|
88
|
+
private hasClassKey;
|
|
89
|
+
private isGroupClassName;
|
|
90
|
+
private getClassKeyAlias;
|
|
91
|
+
private canonicalizeClassName;
|
|
92
|
+
private matchResolvedClassName;
|
|
93
|
+
private createGroupUtility;
|
|
94
|
+
private createAllGroupUtilities;
|
|
95
|
+
private matchRawManagedClassName;
|
|
96
|
+
match(className: string): CompiledUtility | undefined;
|
|
97
|
+
private matchAllResolvedClassName;
|
|
98
|
+
private matchAllRawManagedClassName;
|
|
99
|
+
matchAll(className: string): CompiledUtility[];
|
|
100
|
+
private parseNativeDeclarationProperty;
|
|
101
|
+
private getNativeDeclarationUtility;
|
|
102
|
+
private matchNativeDeclaration;
|
|
103
|
+
private isNativeDeclarationUtility;
|
|
104
|
+
private shouldValidateNativeDeclarationUtility;
|
|
105
|
+
private createNativeDeclarationFallback;
|
|
106
|
+
private createNativeValueNamespaceFallback;
|
|
107
|
+
private createNativeValueNamespaceFastPath;
|
|
108
|
+
private createNativeDeclarationFastPath;
|
|
109
|
+
/**
|
|
110
|
+
* Generate utilities from class name
|
|
111
|
+
* @param className
|
|
112
|
+
* @returns Utility[]
|
|
113
|
+
*/
|
|
114
|
+
generate(className: string, mode?: string): Utility[];
|
|
115
|
+
/**
|
|
116
|
+
* Create utility from given class name
|
|
117
|
+
* @param className
|
|
118
|
+
* @returns Utility
|
|
119
|
+
*/
|
|
120
|
+
createRule(className: string, fixedClass?: string, mode?: string): Utility | undefined;
|
|
121
|
+
createRules(className: string, fixedClass?: string, mode?: string): Utility[];
|
|
122
|
+
protected createRuleWithDefinition(className: string, registeredUtility: CompiledUtility, fixedClass?: string, mode?: string, branchIndex?: number): Utility | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* Create utility from given selector text
|
|
125
|
+
* @param selectorText
|
|
126
|
+
*/
|
|
127
|
+
createRulesFromSelectorText(selectorText: string, layerName?: MasterCSSManifestUtilityLayerName): Utility[] | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* 根據蒐集到的所有 DOM class 重新 create
|
|
130
|
+
*/
|
|
131
|
+
refresh(manifest?: MasterCSSManifest): this;
|
|
132
|
+
reset(): this;
|
|
133
|
+
destroy(): this;
|
|
134
|
+
add(...classNames: string[]): this;
|
|
135
|
+
remove(...classNames: string[]): void;
|
|
136
|
+
getModeSelector(modeName: string): string | undefined;
|
|
137
|
+
}
|
|
138
|
+
export default interface MasterCSS {
|
|
139
|
+
style: HTMLStyleElement | null;
|
|
140
|
+
Native: typeof CSS;
|
|
141
|
+
}
|