@master/css-compiler 2.0.0-rc.85 → 2.0.0-rc.86

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.
@@ -1,12 +1,12 @@
1
1
  import { combineStyleSelectors } from "./utils/selectors.js";
2
2
  import { addCompilerDiagnosticCount, setCompilerDiagnosticCount, timeCompilerDiagnostic } from "./diagnostics.js";
3
3
  import { createMasterCSSManifest, createVariableNameResolver } from "./master-css-manifest.js";
4
- import wrapAtRules from "./utils/wrap-at-rules.js";
4
+ import wrapConditions from "./utils/wrap-conditions.js";
5
5
  import { cssTreeNativeDeclarationMatcher } from "./native-declaration.js";
6
- import { CSSDirectiveError, readCSSDirectiveVariantReference } from "@master/css-schema/css-directives";
7
- import { compareRulePriority, createCompilerCSS, generateAt, generateSelector, parseAt, parseSelector } from "@master/css-engine/compiler";
6
+ import { CSSDirectiveError } from "@master/css-schema/css-directives";
7
+ import { compareRulePriority, createCompilerCSS, generateCondition, generateSelector, parseCondition, parseSelector } from "@master/css-engine/compiler";
8
8
  //#region src/lower-css-directives.ts
9
- const STYLE_AT_FEATURE_REGEX = /\(\s*(width|height|resolution)\s*(>=|<=|>|<)\s*(-?(?:\d+(?:\.\d+)?|\.\d+))([a-z%]*)\s*\)/g;
9
+ const STYLE_CONDITION_FEATURE_REGEX = /\(\s*(width|height|resolution)\s*(>=|<=|>|<)\s*(-?(?:\d+(?:\.\d+)?|\.\d+))([a-z%]*)\s*\)/g;
10
10
  const MEDIA_MODE_NAMES = /* @__PURE__ */ new Set(["light", "dark"]);
11
11
  const DEFAULT_MODE_NONE = "none";
12
12
  const CONDITION_VARIABLE_NAMESPACES = /* @__PURE__ */ new Set(["breakpoint", "container"]);
@@ -26,6 +26,21 @@ function warn(warnings, options, message) {
26
26
  warnings.push(message);
27
27
  options.onWarning?.(message);
28
28
  }
29
+ function cloneConditionPath(conditionPath) {
30
+ return conditionPath?.map((entry) => ({ ...entry }));
31
+ }
32
+ function conditionPathFromConditions(conditions) {
33
+ return conditions?.length ? conditions.map((value) => ({
34
+ type: "condition",
35
+ value
36
+ })) : void 0;
37
+ }
38
+ function getConditionPath(definition) {
39
+ return cloneConditionPath(definition.conditionPath) || conditionPathFromConditions(definition.conditions);
40
+ }
41
+ function conditionPathHasVariants(conditionPath) {
42
+ return conditionPath?.some((entry) => entry.type === "variant") || false;
43
+ }
29
44
  function isNamedDefaultMode(defaultMode) {
30
45
  return typeof defaultMode === "string" && defaultMode !== DEFAULT_MODE_NONE;
31
46
  }
@@ -66,7 +81,8 @@ function cloneUtilityRule(rule) {
66
81
  return {
67
82
  declarations: { ...rule.declarations },
68
83
  ...rule.selector ? { selector: rule.selector } : {},
69
- ...rule.atRules?.length ? { atRules: [...rule.atRules] } : {}
84
+ ...rule.conditions?.length ? { conditions: [...rule.conditions] } : {},
85
+ ...rule.conditionPath?.length ? { conditionPath: cloneConditionPath(rule.conditionPath) } : {}
70
86
  };
71
87
  }
72
88
  function cloneUtility(definition) {
@@ -75,7 +91,8 @@ function cloneUtility(definition) {
75
91
  type: definition.type || "static",
76
92
  ...definition.pattern ? { pattern: {
77
93
  prefix: definition.pattern.prefix,
78
- values: [...definition.pattern.values]
94
+ values: [...definition.pattern.values],
95
+ ...definition.pattern.valueMap ? { valueMap: { ...definition.pattern.valueMap } } : {}
79
96
  } } : {},
80
97
  ...definition.dynamic ? { dynamic: {
81
98
  key: definition.dynamic.key,
@@ -85,7 +102,8 @@ function cloneUtility(definition) {
85
102
  ...definition.dynamic.arbitrary ? { arbitrary: true } : {}
86
103
  } } : {},
87
104
  ...definition.declarations ? { declarations: { ...definition.declarations } } : {},
88
- ...definition.atRules?.length ? { atRules: [...definition.atRules] } : {},
105
+ ...definition.conditions?.length ? { conditions: [...definition.conditions] } : {},
106
+ ...definition.conditionPath?.length ? { conditionPath: cloneConditionPath(definition.conditionPath) } : {},
89
107
  ...definition.rules?.length ? { rules: definition.rules.map(cloneUtilityRule) } : {}
90
108
  };
91
109
  }
@@ -103,7 +121,7 @@ function normalizeDirectiveInput(input = {}, options = {}) {
103
121
  token: variant.token,
104
122
  branches: variant.branches.map((branch) => ({
105
123
  ...branch,
106
- ...branch.atRules?.length ? { atRules: [...branch.atRules] } : {}
124
+ ...branch.conditions?.length ? { conditions: [...branch.conditions] } : {}
107
125
  }))
108
126
  }));
109
127
  if (source.animations) normalized.animations = { ...source.animations };
@@ -152,24 +170,24 @@ function createDirectiveCSS(input, options) {
152
170
  }));
153
171
  return timeCompilerDiagnostic(options.diagnostics, "lower-create-compiler-css-ms", () => createCompilerCSS(manifest, void 0, { nativeDeclarationMatcher: cssTreeNativeDeclarationMatcher }));
154
172
  }
155
- function getUtilityAtRuleDefinitions(utility) {
156
- const atRules = [];
157
- if (utility.atRules) for (const id of [
173
+ function getUtilityConditionDefinitions(utility) {
174
+ const conditions = [];
175
+ if (utility.conditions) for (const id of [
158
176
  "container",
159
177
  "starting-style",
160
178
  "supports",
161
179
  "media",
162
180
  "layer"
163
181
  ]) {
164
- const nodes = utility.atRules[id];
182
+ const nodes = utility.conditions[id];
165
183
  if (!nodes) continue;
166
184
  if (id === "layer" && utility.explicitLayerName) continue;
167
- atRules.push(generateAt({
185
+ conditions.push(generateCondition({
168
186
  id,
169
187
  nodes
170
188
  }));
171
189
  }
172
- return atRules;
190
+ return conditions;
173
191
  }
174
192
  function getComposedUtilitySelector(utility, css) {
175
193
  let selector = utility.selectorTemplate ? "&" : utility.selectorNodes ? generateSelector(utility.selectorNodes, "&") : "&";
@@ -195,156 +213,148 @@ function createStyleDefinitionsFromCompose(definition, css) {
195
213
  return utilities.flatMap((utility) => {
196
214
  const selector = getComposedUtilitySelector(utility, css);
197
215
  const layer = utility.explicitLayerName;
198
- const utilityAtRules = getUtilityAtRuleDefinitions(utility);
199
- return (utility.declarationRules || (utility.declarations ? [{ declarations: utility.declarations }] : [])).map(({ declarations, atRules, selector: ruleSelector }) => ({
216
+ const utilityConditions = getUtilityConditionDefinitions(utility);
217
+ return (utility.declarationRules || (utility.declarations ? [{ declarations: utility.declarations }] : [])).map(({ declarations, conditions, selector: ruleSelector }) => ({
200
218
  utility,
201
219
  selector: ruleSelector ? combineStyleSelectors(selector, ruleSelector) : selector,
202
220
  declarations: cloneDeclarations(declarations, utility.important),
203
221
  ...layer ? { layer } : {},
204
- ...[...utilityAtRules, ...atRules || []].length ? { atRules: [...utilityAtRules, ...atRules || []] } : {}
222
+ ...[...utilityConditions, ...conditions || []].length ? { conditions: [...utilityConditions, ...conditions || []] } : {}
205
223
  }));
206
224
  });
207
225
  }
208
226
  function combineSelectorWrapper(selector, wrapper) {
209
227
  return wrapper.replace(/&/g, selector);
210
228
  }
211
- function mergeResolvedVariantReferenceBranch(branch, resolved, token) {
212
- const nextLayer = resolved.layer || branch.layer;
213
- if (branch.layer && resolved.layer && branch.layer !== resolved.layer) throw new Error(`@variant ${token} cannot assign multiple layers`);
214
- return {
215
- selector: resolved.selector ? combineSelectorWrapper(branch.selector || "&", resolved.selector) : branch.selector,
216
- atRules: [...branch.atRules || [], ...resolved.atRules || []],
217
- ...nextLayer ? { layer: nextLayer } : {}
218
- };
219
- }
220
- function cloneConfiguredVariantBranches(token, css) {
221
- const configuredVariant = css.resolveVariant(token);
222
- if (configuredVariant) return configuredVariant.map((branch) => ({
223
- ...branch.selector ? { selector: branch.selector } : {},
224
- ...branch.atRules?.length ? { atRules: [...branch.atRules] } : {},
225
- ...branch.layer ? { layer: branch.layer } : {}
226
- }));
227
- }
228
- function findClosingParen(value, start) {
229
- let depth = 0;
229
+ function resolveSelectorAliases(selector, css) {
230
+ const selectorTokens = [...css.selectors.keys()].filter((token) => token.startsWith(":")).sort((a, b) => b.length - a.length);
231
+ if (!selectorTokens.length) return selector;
232
+ let result = "";
230
233
  let quote = "";
231
- for (let index = start; index < value.length; index++) {
232
- const char = value[index];
234
+ let attributeDepth = 0;
235
+ for (let index = 0; index < selector.length;) {
236
+ const char = selector[index];
233
237
  if (quote) {
234
- if (char === "\\") index++;
238
+ result += char;
239
+ if (char === "\\") result += selector[++index] || "";
235
240
  else if (char === quote) quote = "";
241
+ index++;
236
242
  continue;
237
243
  }
238
244
  if (char === "\"" || char === "'") {
239
245
  quote = char;
246
+ result += char;
247
+ index++;
240
248
  continue;
241
249
  }
242
- if (char === "(") depth++;
243
- if (char === ")") {
244
- depth--;
245
- if (depth === 0) return index;
246
- }
247
- }
248
- return -1;
249
- }
250
- function resolveSelectorVariantStack(selectorStack, css, token) {
251
- let branches = [{}];
252
- const selectorVariantTokens = [...css.variants.keys()].filter((variantToken) => variantToken.startsWith(":")).sort((a, b) => b.length - a.length);
253
- let index = 0;
254
- let raw = "";
255
- const flushRaw = () => {
256
- if (!raw) return;
257
- const selector = generateSelector(parseSelector(raw, css), "&");
258
- branches = branches.map((branch) => mergeResolvedVariantReferenceBranch(branch, { selector }, token));
259
- raw = "";
260
- };
261
- while (index < selectorStack.length) {
262
- const matchedToken = selectorVariantTokens.find((variantToken) => {
263
- if (!selectorStack.startsWith(variantToken, index)) return false;
264
- const next = selectorStack[index + variantToken.length];
265
- return next === void 0 || next === "(" || !/[-_a-zA-Z0-9]/.test(next);
266
- });
267
- if (!matchedToken) {
268
- raw += selectorStack[index++];
250
+ if (char === "[") {
251
+ attributeDepth++;
252
+ result += char;
253
+ index++;
269
254
  continue;
270
255
  }
271
- const configuredBranches = cloneConfiguredVariantBranches(matchedToken, css);
272
- if (!configuredBranches) {
273
- raw += selectorStack[index++];
256
+ if (char === "]") {
257
+ if (attributeDepth > 0) attributeDepth--;
258
+ result += char;
259
+ index++;
274
260
  continue;
275
261
  }
276
- flushRaw();
277
- index += matchedToken.length;
278
- let suffix = "";
279
- if (selectorStack[index] === "(") {
280
- const end = findClosingParen(selectorStack, index);
281
- if (end !== -1) {
282
- suffix = selectorStack.slice(index, end + 1);
283
- index = end + 1;
262
+ if (!attributeDepth) {
263
+ const matchedToken = selectorTokens.find((token) => {
264
+ if (!selector.startsWith(token, index)) return false;
265
+ const next = selector[index + token.length];
266
+ return next === void 0 || next === "(" || !/[-_a-zA-Z0-9]/.test(next);
267
+ });
268
+ if (matchedToken) {
269
+ const nodes = css.selectors.get(matchedToken);
270
+ if (nodes?.length) {
271
+ result += generateSelector(nodes, "");
272
+ index += matchedToken.length;
273
+ continue;
274
+ }
284
275
  }
285
276
  }
286
- branches = branches.flatMap((branch) => configuredBranches.map((configuredBranch) => {
287
- const selector = configuredBranch.selector && suffix ? configuredBranch.selector + suffix : configuredBranch.selector;
288
- return mergeResolvedVariantReferenceBranch(branch, {
289
- ...configuredBranch,
290
- ...selector ? { selector } : {}
291
- }, token);
292
- }));
277
+ result += char;
278
+ index++;
293
279
  }
294
- flushRaw();
295
- return branches;
280
+ return result;
281
+ }
282
+ function mergeResolvedVariantReferenceBranch(branch, resolved, token) {
283
+ const nextLayer = resolved.layer || branch.layer;
284
+ if (branch.layer && resolved.layer && branch.layer !== resolved.layer) throw new Error(`@variant ${token} cannot assign multiple layers`);
285
+ return {
286
+ selector: resolved.selector ? combineSelectorWrapper(branch.selector || "&", resolved.selector) : branch.selector,
287
+ conditions: [...branch.conditions || [], ...resolved.conditions || []],
288
+ ...nextLayer ? { layer: nextLayer } : {}
289
+ };
296
290
  }
297
- function resolveAtVariantReference(token, css) {
291
+ function cloneConfiguredVariantBranches(token, css) {
292
+ const configuredVariant = css.resolveVariant(token);
293
+ if (configuredVariant) return configuredVariant.map((branch) => ({
294
+ ...branch.selector ? { selector: branch.selector } : {},
295
+ ...branch.conditions?.length ? { conditions: [...branch.conditions] } : branch.conditionNodes?.length ? { conditions: branch.conditionNodes.map((condition) => generateCondition(condition)) } : {},
296
+ ...branch.layer ? { layer: branch.layer } : {}
297
+ }));
298
+ }
299
+ function resolveSelectorVariantReference(token, css) {
300
+ const configuredVariant = cloneConfiguredVariantBranches(token, css);
301
+ if (configuredVariant) return configuredVariant;
302
+ return [{ selector: generateSelector(parseSelector(token, css), "&") }];
303
+ }
304
+ function resolveConditionVariantReference(token, css) {
298
305
  const configuredVariant = cloneConfiguredVariantBranches(token, css);
299
306
  if (configuredVariant) return configuredVariant;
300
- const atToken = token.slice(1);
301
- if (css.modes.includes(atToken)) {
302
- const modeSelector = css.getModeSelector(atToken);
303
- return modeSelector ? [{ selector: `${modeSelector} &` }] : [{ atRules: [`@media (prefers-color-scheme:${atToken})`] }];
307
+ const conditionToken = token.slice(1);
308
+ if (css.modes.includes(conditionToken)) {
309
+ const modeSelector = css.getModeSelector(conditionToken);
310
+ return modeSelector ? [{ selector: `${modeSelector} &` }] : [{ conditions: [`@media (prefers-color-scheme:${conditionToken})`] }];
304
311
  }
305
- if (/^-?[_a-zA-Z][-_a-zA-Z0-9]*$/.test(atToken) && !css.atRules.has(atToken)) throw new Error(`Unknown @variant token: ${token}`);
306
- return [{ atRules: [generateAt(parseAt(atToken, css))] }];
312
+ if (/^-?[_a-zA-Z][-_a-zA-Z0-9]*$/.test(conditionToken) && !css.conditions.has(conditionToken)) throw new Error(`Unknown @variant token: ${token}`);
313
+ return [{ conditions: [generateCondition(parseCondition(conditionToken, css))] }];
307
314
  }
308
315
  function resolveMasterVariantReference(token, css) {
309
- if (!token.startsWith(":") && !token.startsWith("@")) throw new Error(`@variant requires a full variant token: ${token}`);
310
- const [selectorStack = "", ...conditionStacks] = token.split("@");
311
- let branches = selectorStack ? resolveSelectorVariantStack(selectorStack, css, token) : [{}];
316
+ if (!token.startsWith("@")) throw new Error(`@variant requires a full variant token: ${token}`);
317
+ let branches = [{}];
318
+ const conditionStacks = token.slice(1).split("@");
312
319
  for (const conditionStack of conditionStacks) {
313
320
  if (!conditionStack) continue;
314
- const resolvedBranches = resolveAtVariantReference(`@${conditionStack}`, css);
321
+ const resolvedBranches = resolveConditionVariantReference(`@${conditionStack}`, css);
315
322
  branches = branches.flatMap((branch) => resolvedBranches.map((resolved) => mergeResolvedVariantReferenceBranch(branch, resolved, token)));
316
323
  }
317
324
  return branches;
318
325
  }
319
- function resolveConfiguredBranches(atRules, css, selector = "&", layer) {
326
+ function resolveConfiguredBranches(conditionPath, css, selector = "&", layer) {
320
327
  let branches = [{
321
328
  selector,
322
329
  ...layer ? { layer } : {}
323
330
  }];
324
- if (!atRules?.length) return branches;
325
- for (const atRule of atRules) {
326
- const token = readCSSDirectiveVariantReference(atRule);
327
- if (!token) {
331
+ if (!conditionPath?.length) return branches.map((branch) => ({
332
+ ...branch,
333
+ selector: resolveSelectorAliases(branch.selector, css)
334
+ }));
335
+ for (const entry of conditionPath) {
336
+ if (entry.type === "condition") {
328
337
  branches = branches.map((branch) => ({
329
338
  ...branch,
330
- atRules: [...branch.atRules || [], atRule]
339
+ conditions: [...branch.conditions || [], entry.value]
331
340
  }));
332
341
  continue;
333
342
  }
334
- const resolvedBranches = resolveMasterVariantReference(token, css);
343
+ const token = entry.token;
344
+ const resolvedBranches = token.startsWith(":") ? resolveSelectorVariantReference(token, css) : resolveMasterVariantReference(token, css);
335
345
  branches = branches.flatMap((branch) => resolvedBranches.map((resolved) => {
336
346
  const nextLayer = resolved.layer || branch.layer;
337
347
  if (branch.layer && resolved.layer && branch.layer !== resolved.layer) throw new Error(`@variant ${token} cannot assign multiple layers`);
338
348
  return {
339
349
  selector: resolved.selector ? combineSelectorWrapper(branch.selector, resolved.selector) : branch.selector,
340
- atRules: [...branch.atRules || [], ...resolved.atRules || []],
350
+ conditions: [...branch.conditions || [], ...resolved.conditions || []],
341
351
  ...nextLayer ? { layer: nextLayer } : {}
342
352
  };
343
353
  }));
344
354
  }
345
355
  return branches.map((branch) => ({
346
- selector: branch.selector,
347
- ...branch.atRules?.length ? { atRules: branch.atRules } : {},
356
+ selector: resolveSelectorAliases(branch.selector, css),
357
+ ...branch.conditions?.length ? { conditions: branch.conditions } : {},
348
358
  ...branch.layer ? { layer: branch.layer } : {}
349
359
  }));
350
360
  }
@@ -352,11 +362,13 @@ function ensureUtilityRules(definition) {
352
362
  if (!definition.declarations) return;
353
363
  const declarations = definition.declarations;
354
364
  delete definition.declarations;
355
- const atRules = definition.atRules;
356
- delete definition.atRules;
365
+ const conditions = definition.conditions;
366
+ delete definition.conditions;
367
+ const conditionPath = definition.conditionPath;
368
+ delete definition.conditionPath;
357
369
  definition.rules ??= [];
358
370
  definition.rules.push({
359
- ...atRules?.length ? { atRules: [...atRules] } : {},
371
+ ...conditionPath?.length ? { conditionPath: cloneConditionPath(conditionPath) } : conditions?.length ? { conditions: [...conditions] } : {},
360
372
  declarations
361
373
  });
362
374
  }
@@ -366,41 +378,43 @@ function finalizeUtilityDefinitions(input, css, options) {
366
378
  const diagnostics = options.diagnostics;
367
379
  setCompilerDiagnosticCount(diagnostics, "lower-utility-definition-count", utilities.length);
368
380
  for (const definition of utilities) {
369
- if (definition.atRules?.some(readCSSDirectiveVariantReference)) {
370
- const resolvedBranches = timeCompilerDiagnostic(diagnostics, "lower-utility-at-rule-resolution-ms", () => resolveConfiguredBranches(definition.atRules, css));
371
- delete definition.atRules;
381
+ const definitionConditionPath = getConditionPath(definition);
382
+ if (conditionPathHasVariants(definitionConditionPath)) {
383
+ const resolvedBranches = timeCompilerDiagnostic(diagnostics, "lower-utility-condition-resolution-ms", () => resolveConfiguredBranches(definitionConditionPath, css));
384
+ delete definition.conditions;
385
+ delete definition.conditionPath;
372
386
  if (definition.declarations) {
373
387
  definition.rules ??= [];
374
388
  for (const resolved of resolvedBranches) definition.rules.push({
375
389
  declarations: definition.declarations,
376
390
  ...resolved.selector !== "&" ? { selector: resolved.selector } : {},
377
- ...resolved.atRules?.length ? { atRules: resolved.atRules } : {}
391
+ ...resolved.conditions?.length ? { conditions: resolved.conditions } : {}
378
392
  });
379
393
  delete definition.declarations;
380
394
  }
381
395
  }
382
396
  if (!definition.rules?.length) continue;
383
397
  definition.rules = definition.rules.flatMap((rule) => {
384
- return timeCompilerDiagnostic(diagnostics, "lower-utility-rule-resolution-ms", () => resolveConfiguredBranches(rule.atRules, css, rule.selector || "&")).map((resolved) => ({
398
+ return timeCompilerDiagnostic(diagnostics, "lower-utility-rule-resolution-ms", () => resolveConfiguredBranches(getConditionPath(rule), css, rule.selector || "&")).map((resolved) => ({
385
399
  declarations: rule.declarations,
386
400
  ...resolved.selector !== "&" ? { selector: resolved.selector } : {},
387
- ...resolved.atRules?.length ? { atRules: resolved.atRules } : {}
401
+ ...resolved.conditions?.length ? { conditions: resolved.conditions } : {}
388
402
  }));
389
403
  });
390
404
  }
391
405
  }
392
- function getStyleMergeBucketKey(selector, atRules, layer) {
406
+ function getStyleMergeBucketKey(selector, conditions, layer) {
393
407
  return JSON.stringify([
394
408
  layer || "",
395
409
  selector,
396
- atRules || []
410
+ conditions || []
397
411
  ]);
398
412
  }
399
- function pushStyleMergeEvent(buckets, selector, atRules, layer, event) {
400
- const key = getStyleMergeBucketKey(selector, atRules, layer);
413
+ function pushStyleMergeEvent(buckets, selector, conditions, layer, event) {
414
+ const key = getStyleMergeBucketKey(selector, conditions, layer);
401
415
  const bucket = buckets.get(key) || {
402
416
  selector,
403
- ...atRules?.length ? { atRules } : {},
417
+ ...conditions?.length ? { conditions } : {},
404
418
  ...layer ? { layer } : {},
405
419
  order: event.order,
406
420
  events: []
@@ -443,19 +457,19 @@ function createMergedStyleDefinition(bucket) {
443
457
  return {
444
458
  selector: bucket.selector,
445
459
  declarations,
446
- ...bucket.atRules?.length ? { atRules: bucket.atRules } : {},
460
+ ...bucket.conditions?.length ? { conditions: bucket.conditions } : {},
447
461
  ...bucket.layer ? { layer: bucket.layer } : {}
448
462
  };
449
463
  }
450
- function normalizeStyleAtFeatureValue(value, unit, rootSize) {
464
+ function normalizeStyleConditionFeatureValue(value, unit, rootSize) {
451
465
  if (unit === "px") return value / rootSize;
452
466
  return value;
453
467
  }
454
- function getStyleAtRuleFeatures(atRules, rootSize) {
468
+ function getStyleConditionFeatures(conditions, rootSize) {
455
469
  const featureMap = /* @__PURE__ */ new Map();
456
- for (const atRule of atRules || []) for (const match of atRule.matchAll(STYLE_AT_FEATURE_REGEX)) {
470
+ for (const condition of conditions || []) for (const match of condition.matchAll(STYLE_CONDITION_FEATURE_REGEX)) {
457
471
  const [, name, operator, rawValue, unit] = match;
458
- const value = normalizeStyleAtFeatureValue(Number(rawValue), unit, rootSize);
472
+ const value = normalizeStyleConditionFeatureValue(Number(rawValue), unit, rootSize);
459
473
  const entry = featureMap.get(name) ?? {};
460
474
  switch (operator) {
461
475
  case ">":
@@ -479,7 +493,7 @@ function getStyleAtRuleFeatures(atRules, rootSize) {
479
493
  entry.max ?? Number.MAX_SAFE_INTEGER
480
494
  ]).sort(([a], [b]) => a.localeCompare(b, void 0, { numeric: true }));
481
495
  }
482
- function compareStyleAtRuleFeatures(a, b) {
496
+ function compareStyleConditionFeatures(a, b) {
483
497
  const len = Math.max(a.length, b.length);
484
498
  for (let index = 0; index < len; index++) {
485
499
  const left = a[index];
@@ -500,14 +514,14 @@ function compareStyleAtRuleFeatures(a, b) {
500
514
  }
501
515
  function compareStyleMergeBuckets(a, b, rootSize) {
502
516
  if ((a.layer || "components") === (b.layer || "components") && a.selector === b.selector) {
503
- const atRuleStateA = a.atRules?.length ? 1 : 0;
504
- const atRuleStateB = b.atRules?.length ? 1 : 0;
505
- if (atRuleStateA !== atRuleStateB) return atRuleStateA - atRuleStateB;
506
- if (atRuleStateA && atRuleStateB) {
507
- const featuresA = getStyleAtRuleFeatures(a.atRules, rootSize);
508
- const featuresB = getStyleAtRuleFeatures(b.atRules, rootSize);
517
+ const conditionStateA = a.conditions?.length ? 1 : 0;
518
+ const conditionStateB = b.conditions?.length ? 1 : 0;
519
+ if (conditionStateA !== conditionStateB) return conditionStateA - conditionStateB;
520
+ if (conditionStateA && conditionStateB) {
521
+ const featuresA = getStyleConditionFeatures(a.conditions, rootSize);
522
+ const featuresB = getStyleConditionFeatures(b.conditions, rootSize);
509
523
  if (featuresA.length && featuresB.length) {
510
- const featureCompare = compareStyleAtRuleFeatures(featuresA, featuresB);
524
+ const featureCompare = compareStyleConditionFeatures(featuresA, featuresB);
511
525
  if (featureCompare !== 0) return featureCompare;
512
526
  }
513
527
  }
@@ -519,19 +533,19 @@ function createMergedStyleDefinitions(definitions, css, targetLayer) {
519
533
  for (const definition of definitions) if (definition.type === "compose") {
520
534
  const composedDefinitions = createStyleDefinitionsFromCompose(definition, css);
521
535
  for (const composedDefinition of composedDefinitions) {
522
- const { atRules: composedAtRules, ...composedDefinitionWithoutAtRules } = composedDefinition;
536
+ const { conditions: composedConditions, ...composedDefinitionWithoutConditions } = composedDefinition;
523
537
  const selector = combineStyleSelectors(definition.selector, composedDefinition.selector);
524
- const resolvedBranches = resolveConfiguredBranches([...definition.atRules || [], ...composedAtRules || []], css, selector, targetLayer || composedDefinitionWithoutAtRules.layer);
525
- for (const resolved of resolvedBranches) pushStyleMergeEvent(buckets, resolved.selector, resolved.atRules, resolved.layer, {
538
+ const resolvedBranches = resolveConfiguredBranches([...getConditionPath(definition) || [], ...conditionPathFromConditions(composedConditions) || []], css, selector, targetLayer || composedDefinitionWithoutConditions.layer);
539
+ for (const resolved of resolvedBranches) pushStyleMergeEvent(buckets, resolved.selector, resolved.conditions, resolved.layer, {
526
540
  type: "compose",
527
541
  order: definition.order,
528
- utility: composedDefinitionWithoutAtRules.utility,
529
- declarations: composedDefinitionWithoutAtRules.declarations
542
+ utility: composedDefinitionWithoutConditions.utility,
543
+ declarations: composedDefinitionWithoutConditions.declarations
530
544
  });
531
545
  }
532
546
  } else {
533
- const resolvedBranches = resolveConfiguredBranches(definition.atRules, css, definition.selector, targetLayer || definition.layer);
534
- for (const resolved of resolvedBranches) pushStyleMergeEvent(buckets, resolved.selector, resolved.atRules, resolved.layer, {
547
+ const resolvedBranches = resolveConfiguredBranches(getConditionPath(definition), css, definition.selector, targetLayer || definition.layer);
548
+ for (const resolved of resolvedBranches) pushStyleMergeEvent(buckets, resolved.selector, resolved.conditions, resolved.layer, {
535
549
  type: "native",
536
550
  order: definition.order,
537
551
  declarations: definition.declarations
@@ -621,7 +635,7 @@ function createManagedStyleDefinitionPlan(groups, keysByName) {
621
635
  function renderStyleDefinitions(definitions) {
622
636
  return definitions.map((definition) => {
623
637
  const body = Object.entries(definition.declarations).map(([propertyName, value]) => `${propertyName}:${value}`).join(";");
624
- return wrapAtRules(`${definition.selector}{${body}}`, definition.atRules);
638
+ return wrapConditions(`${definition.selector}{${body}}`, definition.conditions);
625
639
  }).join("");
626
640
  }
627
641
  function getStaticUtilityDefinition(input, name, layer) {
@@ -644,9 +658,9 @@ function pushStaticUtilityStyleRule(definition, styleDefinition) {
644
658
  const rule = {
645
659
  declarations: styleDefinition.declarations,
646
660
  ...styleDefinition.selector !== "&" ? { selector: styleDefinition.selector } : {},
647
- ...styleDefinition.atRules?.length ? { atRules: styleDefinition.atRules } : {}
661
+ ...styleDefinition.conditions?.length ? { conditions: styleDefinition.conditions } : {}
648
662
  };
649
- if (!definition.declarations && !definition.rules?.length && !rule.selector && !rule.atRules?.length) {
663
+ if (!definition.declarations && !definition.rules?.length && !rule.selector && !rule.conditions?.length) {
650
664
  definition.declarations = rule.declarations;
651
665
  return;
652
666
  }
@@ -1,7 +1,6 @@
1
1
  import { CSSDirectiveManifestInput as CSSDirectiveManifestInput$1, CSSDirectiveVariableDefinition } from "@master/css-schema/css-directives";
2
2
  import { MasterCSSManifest } from "@master/css-schema/manifest";
3
3
  import { CompilerDiagnosticRecorder } from "./diagnostics.js";
4
-
5
4
  //#region src/master-css-manifest.d.ts
6
5
  type CSSDirectiveManifestInput = CSSDirectiveManifestInput$1;
7
6
  interface CreateMasterCSSManifestOptions {