@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.
- package/dist/browser.d.ts +3 -4
- package/dist/core.d.ts +1 -2
- package/dist/core.js +117 -64
- package/dist/css-transform.d.ts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/lexer/imports.d.ts +0 -1
- package/dist/lexer/source.d.ts +0 -1
- package/dist/lexer/standalone-master.d.ts +0 -1
- package/dist/lower-css-directives.d.ts +0 -1
- package/dist/lower-css-directives.js +158 -144
- package/dist/master-css-manifest.d.ts +0 -1
- package/dist/master-css-manifest.js +127 -65
- package/dist/native-declaration.d.ts +0 -1
- package/dist/stylesheet-value.d.ts +9 -0
- package/dist/stylesheet-value.js +141 -0
- package/dist/utils/selectors.js +6 -1
- package/dist/utils/wrap-conditions.d.ts +4 -0
- package/dist/utils/wrap-conditions.js +11 -0
- package/package.json +5 -5
- package/dist/utils/wrap-at-rules.d.ts +0 -4
- package/dist/utils/wrap-at-rules.js +0 -11
package/dist/browser.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import init from "lightningcss-wasm";
|
|
|
2
2
|
import { MasterCSSManifest } from "@master/css-schema/manifest";
|
|
3
3
|
import { CompileCSSOptions, CompileCSSResult } from "./core.js";
|
|
4
4
|
export type * from "./core.js";
|
|
5
|
-
|
|
6
5
|
//#region src/browser.d.ts
|
|
7
6
|
type CompileCSSManifestSourceOptions = CompileCSSOptions & {
|
|
8
7
|
baseManifest?: MasterCSSManifest;
|
|
@@ -15,12 +14,12 @@ declare function initCSSCompiler(input?: Parameters<typeof init>[0]): Promise<vo
|
|
|
15
14
|
declare function compileCSS(source: string, options?: CompileCSSOptions): Promise<CompileCSSResult>;
|
|
16
15
|
declare function compileCSSManifest(source: string, options?: CompileCSSManifestSourceOptions): Promise<CompileCSSManifestResult>;
|
|
17
16
|
declare function parseDirectives(source: string, options?: CompileCSSOptions): Promise<{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
extractionPolicy: import("@master/css-schema/css-directives").CSSDirectiveExtractionPolicy;
|
|
17
|
+
manifestInput: import("~/packages/schema/src/css-directives").CSSDirectiveManifestInput;
|
|
18
|
+
extractionPolicy: import("~/packages/schema/src/css-directives").CSSDirectiveExtractionPolicy;
|
|
21
19
|
classNames: string[];
|
|
22
20
|
nativeClassNames: string[];
|
|
23
21
|
warnings: string[];
|
|
22
|
+
styleDefinitions?: import("~/packages/schema/src/css-directives").CSSDirectiveStyleDefinition[] | undefined;
|
|
24
23
|
}>;
|
|
25
24
|
//#endregion
|
|
26
25
|
export { CompileCSSManifestResult, CompileCSSManifestSourceOptions, compileCSS, compileCSSManifest, initCSSCompiler, parseDirectives };
|
package/dist/core.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { CSSDirectiveManifestInput, CSSDirectiveReference, CSSDirectiveResult, C
|
|
|
2
2
|
import { CSSDirectiveRuleRange, createSourceLocationResolver } from "@master/css-lexer";
|
|
3
3
|
import { CSSTransform, setCSSTransform } from "./css-transform.js";
|
|
4
4
|
import { StandaloneCSSDirectiveStatement, StandaloneMasterDirectiveStatement, collectStandaloneCSSDirectiveExtractionPolicy, createCSSDirectiveExtractionPolicy, findStandaloneCSSDirectiveStatements, findStandaloneMasterDirectiveStatements, mergeCSSDirectiveExtractionPolicy, removeStandaloneCSSDirectives, removeStandaloneMasterDirectives } from "./lexer/standalone-master.js";
|
|
5
|
-
|
|
6
5
|
//#region src/core.d.ts
|
|
7
6
|
interface CompileCSSOptions {
|
|
8
7
|
classes?: string[];
|
|
@@ -39,12 +38,12 @@ declare function removeCSSReferenceStatements(source: string, filename?: string)
|
|
|
39
38
|
declare function maskManagedPatternEntryNames(source: string): string;
|
|
40
39
|
declare function compileCSS(source: string, options?: CompileCSSOptions): CompileCSSResult;
|
|
41
40
|
declare function parseDirectives(source: string, options?: CompileCSSOptions): {
|
|
42
|
-
styleDefinitions?: CSSDirectiveStyleDefinition[] | undefined;
|
|
43
41
|
manifestInput: CSSDirectiveManifestInput;
|
|
44
42
|
extractionPolicy: import("@master/css-schema/css-directives").CSSDirectiveExtractionPolicy;
|
|
45
43
|
classNames: string[];
|
|
46
44
|
nativeClassNames: string[];
|
|
47
45
|
warnings: string[];
|
|
46
|
+
styleDefinitions?: CSSDirectiveStyleDefinition[] | undefined;
|
|
48
47
|
};
|
|
49
48
|
//#endregion
|
|
50
49
|
export { CSSReferenceStatement, type CSSTransform, CompileCSSFileOptions, CompileCSSOptions, CompileCSSResult, ParsedDirectives, ResolvedCSSImportGraph, type StandaloneCSSDirectiveStatement, type StandaloneMasterDirectiveStatement, collectStandaloneCSSDirectiveExtractionPolicy, compileCSS, createCSSDirectiveExtractionPolicy, findCSSReferenceStatements, findStandaloneCSSDirectiveStatements, findStandaloneMasterDirectiveStatements, maskManagedPatternEntryNames, mergeCSSDirectiveExtractionPolicy, parseDirectives, removeCSSReferenceStatements, removeStandaloneCSSDirectives, removeStandaloneMasterDirectives, setCSSTransform };
|
package/dist/core.js
CHANGED
|
@@ -1,9 +1,33 @@
|
|
|
1
1
|
import { decodeCSS, encodeCSS, getCSSTransform, setCSSTransform } from "./css-transform.js";
|
|
2
2
|
import { collectStandaloneCSSDirectiveExtractionPolicy, createCSSDirectiveExtractionPolicy, findStandaloneCSSDirectiveStatements, findStandaloneMasterDirectiveStatements, mergeCSSDirectiveExtractionPolicy, removeStandaloneCSSDirectives, removeStandaloneMasterDirectives } from "./lexer/standalone-master.js";
|
|
3
3
|
import { combineSelectorLists } from "./utils/selectors.js";
|
|
4
|
-
import {
|
|
4
|
+
import { normalizeStylesheetValue } from "./stylesheet-value.js";
|
|
5
|
+
import { CSSDirectiveError, createCSSDirectiveSourceReference } from "@master/css-schema/css-directives";
|
|
5
6
|
import { collectCSSDirectiveRanges, collectMasterCSSClassListTokenRanges, createSourceLocationResolver, findCSSBlockEnd, findCSSClosingQuote, findCSSStatementEnd, removeSourceRanges, replaceSourceRanges, skipCSSWhitespace } from "@master/css-lexer";
|
|
6
7
|
//#region src/core.ts
|
|
8
|
+
function conditionEntry(value) {
|
|
9
|
+
return {
|
|
10
|
+
type: "condition",
|
|
11
|
+
value
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function variantEntry(token) {
|
|
15
|
+
return {
|
|
16
|
+
type: "variant",
|
|
17
|
+
token
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function cloneConditionPath(conditionPath) {
|
|
21
|
+
return conditionPath?.map((entry) => ({ ...entry }));
|
|
22
|
+
}
|
|
23
|
+
function createConditionPathProperties(conditionPath) {
|
|
24
|
+
if (!conditionPath?.length) return {};
|
|
25
|
+
const conditions = conditionPath.every((entry) => entry.type === "condition") ? conditionPath.map((entry) => entry.value) : void 0;
|
|
26
|
+
return {
|
|
27
|
+
...conditions?.length ? { conditions } : {},
|
|
28
|
+
conditionPath: cloneConditionPath(conditionPath)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
7
31
|
const MASTER_CUSTOM_AT_RULES = {
|
|
8
32
|
settings: {
|
|
9
33
|
prelude: "*",
|
|
@@ -147,7 +171,7 @@ function normalizeThemeTokenName(property) {
|
|
|
147
171
|
}
|
|
148
172
|
function defineThemeVariable(manifestInput, property, rawValue, mode, inline, isStatic) {
|
|
149
173
|
const name = normalizeThemeTokenName(property);
|
|
150
|
-
const value = parseVariableValue(rawValue);
|
|
174
|
+
const value = parseVariableValue(normalizeStylesheetValue(rawValue, { replacePipes: true }).value);
|
|
151
175
|
if (mode) addThemeMode(manifestInput, mode);
|
|
152
176
|
manifestInput.variables ??= [];
|
|
153
177
|
const definition = {
|
|
@@ -302,6 +326,9 @@ function formatDeclarationValue(declaration) {
|
|
|
302
326
|
const colonIndex = declarationText.indexOf(":");
|
|
303
327
|
return formatCSSNumberLiterals(declarationText.slice(colonIndex + 1).trim());
|
|
304
328
|
}
|
|
329
|
+
function normalizeDeclarationValue(value) {
|
|
330
|
+
return normalizeStylesheetValue(value).value;
|
|
331
|
+
}
|
|
305
332
|
function normalizeNumberText(value) {
|
|
306
333
|
const [rawMantissa, rawExponent] = value.toLowerCase().replace("e+", "e").split("e");
|
|
307
334
|
let mantissa = rawMantissa.replace(/^\+/, "");
|
|
@@ -636,8 +663,8 @@ function getDeclarationName(declaration) {
|
|
|
636
663
|
}
|
|
637
664
|
function collectDeclarations(block) {
|
|
638
665
|
const declarations = {};
|
|
639
|
-
for (const declaration of block.declarations || []) declarations[getDeclarationName(declaration)] = formatDeclarationValue(declaration);
|
|
640
|
-
for (const declaration of block.importantDeclarations || []) declarations[getDeclarationName(declaration)] = `${formatDeclarationValue(declaration)} !important`;
|
|
666
|
+
for (const declaration of block.declarations || []) declarations[getDeclarationName(declaration)] = normalizeDeclarationValue(formatDeclarationValue(declaration));
|
|
667
|
+
for (const declaration of block.importantDeclarations || []) declarations[getDeclarationName(declaration)] = `${normalizeDeclarationValue(formatDeclarationValue(declaration))} !important`;
|
|
641
668
|
return declarations;
|
|
642
669
|
}
|
|
643
670
|
const WEBKIT_PAIRED_DECLARATIONS = {
|
|
@@ -719,9 +746,11 @@ function parseThemeDeclarations(block, manifestInput, mode, inline, isStatic) {
|
|
|
719
746
|
}
|
|
720
747
|
function parseCustomVariantPrelude(prelude) {
|
|
721
748
|
const trimmed = prelude.trim();
|
|
722
|
-
|
|
749
|
+
if (trimmed.startsWith("::") || trimmed.startsWith(":")) throw new Error("@custom-variant only defines condition variants. Use nested selectors directly for selector behavior.");
|
|
750
|
+
if (trimmed.startsWith("@")) throw new Error(`@custom-variant uses bare condition variant names: write "@custom-variant ${trimmed.slice(1)}"`);
|
|
751
|
+
const tokenMatch = /^[-_a-zA-Z][-_a-zA-Z0-9]*$/.exec(trimmed);
|
|
723
752
|
if (!tokenMatch) return;
|
|
724
|
-
return { token: tokenMatch[
|
|
753
|
+
return { token: `@${tokenMatch[0]}` };
|
|
725
754
|
}
|
|
726
755
|
function defineVariant(manifestInput, variant) {
|
|
727
756
|
manifestInput.variants ??= [];
|
|
@@ -743,13 +772,13 @@ function createVariantTemplateBranch(path) {
|
|
|
743
772
|
const selector = path.selectors.reduce((current, selectorTemplate) => selectorTemplate.replace(/&/g, current), "&");
|
|
744
773
|
return {
|
|
745
774
|
...selector !== "&" ? { selector } : {},
|
|
746
|
-
...path.
|
|
775
|
+
...path.conditions.length ? { conditions: [...path.conditions] } : {},
|
|
747
776
|
...path.layer ? { layer: path.layer } : {}
|
|
748
777
|
};
|
|
749
778
|
}
|
|
750
779
|
function collectVariantTemplateBranches(rules, token, path = {
|
|
751
780
|
selectors: [],
|
|
752
|
-
|
|
781
|
+
conditions: []
|
|
753
782
|
}) {
|
|
754
783
|
const branches = [];
|
|
755
784
|
for (const child of rules) {
|
|
@@ -786,7 +815,7 @@ function collectVariantTemplateBranches(rules, token, path = {
|
|
|
786
815
|
if (!atRule) throw new Error(`Unsupported nested at-rule in @custom-variant ${token}`);
|
|
787
816
|
branches.push(...collectVariantTemplateBranches(nestedAtRuleChildren, token, {
|
|
788
817
|
...path,
|
|
789
|
-
|
|
818
|
+
conditions: [...path.conditions, atRule]
|
|
790
819
|
}));
|
|
791
820
|
continue;
|
|
792
821
|
}
|
|
@@ -916,11 +945,15 @@ function parseMasterVariantBlock(rule) {
|
|
|
916
945
|
if (shorthandToken && prelude) throw new Error(`@${rule.value.name} does not accept a prelude`);
|
|
917
946
|
const token = shorthandToken || prelude;
|
|
918
947
|
if (!token) throw new Error("@variant requires a Master CSS variant");
|
|
919
|
-
if (
|
|
948
|
+
if (!shorthandToken) {
|
|
949
|
+
if (token.startsWith("@")) throw new Error(`@variant uses bare condition variant names: write "@variant ${token.slice(1)}"`);
|
|
950
|
+
if (token.startsWith("::") || token.startsWith(":")) throw new Error("@variant only applies condition variants. Use nested selectors directly for selector behavior.");
|
|
951
|
+
if (!/^\S+$/.test(token)) throw new Error("@variant requires a full condition variant token");
|
|
952
|
+
}
|
|
920
953
|
const rules = rule.value.body?.value;
|
|
921
954
|
if (!Array.isArray(rules)) throw new Error("@variant requires a style block");
|
|
922
955
|
return {
|
|
923
|
-
token,
|
|
956
|
+
token: shorthandToken || (token.startsWith(":") ? token : `@${token}`),
|
|
924
957
|
rules
|
|
925
958
|
};
|
|
926
959
|
}
|
|
@@ -974,7 +1007,7 @@ const EMPTY_DECLARATION_BLOCK = {
|
|
|
974
1007
|
declarations: [],
|
|
975
1008
|
importantDeclarations: []
|
|
976
1009
|
};
|
|
977
|
-
function parseStyleDefinitionBody(parsed, selectorDefinition, items,
|
|
1010
|
+
function parseStyleDefinitionBody(parsed, selectorDefinition, items, conditionPath = [], layer, name = selectorDefinition.name) {
|
|
978
1011
|
const definitions = getParsedStyleDefinitions(parsed);
|
|
979
1012
|
for (const item of items) {
|
|
980
1013
|
if (item.type === "compose") {
|
|
@@ -987,7 +1020,7 @@ function parseStyleDefinitionBody(parsed, selectorDefinition, items, atRules = [
|
|
|
987
1020
|
...item.directiveSource ? { directiveSource: item.directiveSource } : {},
|
|
988
1021
|
...selectorDefinition.source ? { selectorSource: selectorDefinition.source } : {},
|
|
989
1022
|
...name ? { name } : {},
|
|
990
|
-
...
|
|
1023
|
+
...createConditionPathProperties(conditionPath),
|
|
991
1024
|
...layer ? { layer } : {}
|
|
992
1025
|
})));
|
|
993
1026
|
continue;
|
|
@@ -1001,41 +1034,41 @@ function parseStyleDefinitionBody(parsed, selectorDefinition, items, atRules = [
|
|
|
1001
1034
|
...selectorDefinition.source ? { selectorSource: selectorDefinition.source } : {},
|
|
1002
1035
|
...name ? { name } : {},
|
|
1003
1036
|
declarations: item.declarations,
|
|
1004
|
-
...
|
|
1037
|
+
...createConditionPathProperties(conditionPath),
|
|
1005
1038
|
...layer ? { layer } : {}
|
|
1006
1039
|
});
|
|
1007
1040
|
continue;
|
|
1008
1041
|
}
|
|
1009
|
-
if (name) parseNestedManagedStyleChildRule(item.rule, parsed, selectorDefinition,
|
|
1010
|
-
else parseNestedNativeStyleChildRule(item.rule, parsed, selectorDefinition,
|
|
1042
|
+
if (name) parseNestedManagedStyleChildRule(item.rule, parsed, selectorDefinition, conditionPath, layer);
|
|
1043
|
+
else parseNestedNativeStyleChildRule(item.rule, parsed, selectorDefinition, conditionPath);
|
|
1011
1044
|
}
|
|
1012
1045
|
if (name && !parsed.classNames.includes(name)) parsed.classNames.push(name);
|
|
1013
1046
|
}
|
|
1014
|
-
function parseStyleRuleBody(rules, parsed, selectorDefinition,
|
|
1015
|
-
parseStyleDefinitionBody(parsed, selectorDefinition, collectDirectiveStyleRuleBody(EMPTY_DECLARATION_BLOCK, rules, parsed),
|
|
1047
|
+
function parseStyleRuleBody(rules, parsed, selectorDefinition, conditionPath = [], layer, name = selectorDefinition.name) {
|
|
1048
|
+
parseStyleDefinitionBody(parsed, selectorDefinition, collectDirectiveStyleRuleBody(EMPTY_DECLARATION_BLOCK, rules, parsed), conditionPath, layer, name);
|
|
1016
1049
|
}
|
|
1017
|
-
function parseNestedManagedStyleChildRule(child, parsed, parentSelectorDefinition,
|
|
1050
|
+
function parseNestedManagedStyleChildRule(child, parsed, parentSelectorDefinition, conditionPath, layer) {
|
|
1018
1051
|
assertNotSlotRule(child);
|
|
1019
1052
|
if (child.type === "layer-block") throw new Error("Nested @layer blocks are not allowed inside managed style definitions");
|
|
1020
1053
|
const masterVariantBlock = parseMasterVariantBlock(child);
|
|
1021
1054
|
if (masterVariantBlock) {
|
|
1022
|
-
parseStyleRuleBody(masterVariantBlock.rules, parsed, parentSelectorDefinition, [...
|
|
1055
|
+
parseStyleRuleBody(masterVariantBlock.rules, parsed, parentSelectorDefinition, [...conditionPath, variantEntry(masterVariantBlock.token)], layer);
|
|
1023
1056
|
return;
|
|
1024
1057
|
}
|
|
1025
1058
|
const nestedAtRuleChildren = getNestedAtRuleChildren(child);
|
|
1026
1059
|
if (nestedAtRuleChildren) {
|
|
1027
1060
|
const atRule = formatNestedAtRule(child);
|
|
1028
1061
|
if (!atRule) throw new Error("Unsupported nested at-rule in @master");
|
|
1029
|
-
parseStyleRuleBody(nestedAtRuleChildren, parsed, parentSelectorDefinition, [...
|
|
1062
|
+
parseStyleRuleBody(nestedAtRuleChildren, parsed, parentSelectorDefinition, [...conditionPath, conditionEntry(atRule)], layer);
|
|
1030
1063
|
return;
|
|
1031
1064
|
}
|
|
1032
1065
|
if (child.type === "style") {
|
|
1033
|
-
parseManagedStyleRule(child, parsed,
|
|
1066
|
+
parseManagedStyleRule(child, parsed, conditionPath, layer, parentSelectorDefinition);
|
|
1034
1067
|
return;
|
|
1035
1068
|
}
|
|
1036
1069
|
throw new Error("Style definitions only accept declarations, @compose, nested selectors, and nested at-rules");
|
|
1037
1070
|
}
|
|
1038
|
-
function parseManagedStyleRule(rule, parsed,
|
|
1071
|
+
function parseManagedStyleRule(rule, parsed, conditionPath = [], layer, parentSelectorDefinition) {
|
|
1039
1072
|
const selectorDefinition = parentSelectorDefinition ? (() => {
|
|
1040
1073
|
const selectors = combineStyleSelectorLists(parentSelectorDefinition.selectors, rule.value.selectors);
|
|
1041
1074
|
return {
|
|
@@ -1047,7 +1080,7 @@ function parseManagedStyleRule(rule, parsed, atRules = [], layer, parentSelector
|
|
|
1047
1080
|
})() : parseManagedStyleDefinitionSelector(rule.value.selectors);
|
|
1048
1081
|
if (!selectorDefinition) throw new Error("Managed style definition selector must start with a single class selector");
|
|
1049
1082
|
selectorDefinition.source ||= createSelectorSourceReference(parsed, rule);
|
|
1050
|
-
parseStyleDefinitionBody(parsed, selectorDefinition, collectDirectiveStyleRule(rule, parsed),
|
|
1083
|
+
parseStyleDefinitionBody(parsed, selectorDefinition, collectDirectiveStyleRule(rule, parsed), conditionPath, layer);
|
|
1051
1084
|
}
|
|
1052
1085
|
function parseNativeSelectorDefinition(selectors, parentSelectorDefinition) {
|
|
1053
1086
|
const selectorTexts = parentSelectorDefinition ? combineStyleSelectorLists(parentSelectorDefinition.selectors, selectors) : selectors.map((selector) => formatSelectors([selector]));
|
|
@@ -1056,7 +1089,7 @@ function parseNativeSelectorDefinition(selectors, parentSelectorDefinition) {
|
|
|
1056
1089
|
selector: selectorTexts.join(",")
|
|
1057
1090
|
};
|
|
1058
1091
|
}
|
|
1059
|
-
function parseNativeRuleBody(rules, parsed,
|
|
1092
|
+
function parseNativeRuleBody(rules, parsed, conditionPath = [], parentSelectorDefinition) {
|
|
1060
1093
|
for (const child of rules) {
|
|
1061
1094
|
assertNotSlotRule(child);
|
|
1062
1095
|
const compose = parseComposeRule(child, parsed);
|
|
@@ -1065,7 +1098,7 @@ function parseNativeRuleBody(rules, parsed, atRules = [], parentSelectorDefiniti
|
|
|
1065
1098
|
type: "compose",
|
|
1066
1099
|
classNames: compose.classNames,
|
|
1067
1100
|
...compose.directiveSource ? { directiveSource: compose.directiveSource } : {}
|
|
1068
|
-
}],
|
|
1101
|
+
}], conditionPath, void 0, void 0);
|
|
1069
1102
|
continue;
|
|
1070
1103
|
}
|
|
1071
1104
|
if (child.type === "nested-declarations" && parentSelectorDefinition) {
|
|
@@ -1073,23 +1106,23 @@ function parseNativeRuleBody(rules, parsed, atRules = [], parentSelectorDefiniti
|
|
|
1073
1106
|
if (Object.keys(declarations).length) parseStyleDefinitionBody(parsed, parentSelectorDefinition, [{
|
|
1074
1107
|
type: "declarations",
|
|
1075
1108
|
declarations
|
|
1076
|
-
}],
|
|
1109
|
+
}], conditionPath, void 0, void 0);
|
|
1077
1110
|
continue;
|
|
1078
1111
|
}
|
|
1079
1112
|
const masterVariantBlock = parseMasterVariantBlock(child);
|
|
1080
1113
|
if (masterVariantBlock) {
|
|
1081
|
-
parseNativeRuleBody(masterVariantBlock.rules, parsed, [...
|
|
1114
|
+
parseNativeRuleBody(masterVariantBlock.rules, parsed, [...conditionPath, variantEntry(masterVariantBlock.token)], parentSelectorDefinition);
|
|
1082
1115
|
continue;
|
|
1083
1116
|
}
|
|
1084
1117
|
const nestedAtRuleChildren = getNestedAtRuleChildren(child);
|
|
1085
1118
|
if (nestedAtRuleChildren) {
|
|
1086
1119
|
const atRule = formatNestedAtRule(child);
|
|
1087
1120
|
if (!atRule) throw new Error("Unsupported nested at-rule in native CSS");
|
|
1088
|
-
parseNativeRuleBody(nestedAtRuleChildren, parsed, [...
|
|
1121
|
+
parseNativeRuleBody(nestedAtRuleChildren, parsed, [...conditionPath, conditionEntry(atRule)], parentSelectorDefinition);
|
|
1089
1122
|
continue;
|
|
1090
1123
|
}
|
|
1091
1124
|
if (child.type === "style") {
|
|
1092
|
-
parseNativeStyleRule(child, parsed,
|
|
1125
|
+
parseNativeStyleRule(child, parsed, conditionPath, parentSelectorDefinition);
|
|
1093
1126
|
continue;
|
|
1094
1127
|
}
|
|
1095
1128
|
if (child.type === "keyframes") throw new Error("@keyframes is not allowed inside @variant. Move managed animation definitions to top-level @theme.");
|
|
@@ -1097,30 +1130,30 @@ function parseNativeRuleBody(rules, parsed, atRules = [], parentSelectorDefiniti
|
|
|
1097
1130
|
if (child.type === "nested-declarations") throw new Error("Native @variant blocks only accept style rules, declarations, @compose, and nested at-rules");
|
|
1098
1131
|
}
|
|
1099
1132
|
}
|
|
1100
|
-
function parseNestedNativeStyleChildRule(child, parsed, parentSelectorDefinition,
|
|
1133
|
+
function parseNestedNativeStyleChildRule(child, parsed, parentSelectorDefinition, conditionPath) {
|
|
1101
1134
|
assertNotSlotRule(child);
|
|
1102
1135
|
const masterVariantBlock = parseMasterVariantBlock(child);
|
|
1103
1136
|
if (masterVariantBlock) {
|
|
1104
|
-
parseNativeRuleBody(masterVariantBlock.rules, parsed, [...
|
|
1137
|
+
parseNativeRuleBody(masterVariantBlock.rules, parsed, [...conditionPath, variantEntry(masterVariantBlock.token)], parentSelectorDefinition);
|
|
1105
1138
|
return;
|
|
1106
1139
|
}
|
|
1107
1140
|
const nestedAtRuleChildren = getNestedAtRuleChildren(child);
|
|
1108
1141
|
if (nestedAtRuleChildren) {
|
|
1109
1142
|
const atRule = formatNestedAtRule(child);
|
|
1110
1143
|
if (!atRule) throw new Error("Unsupported nested at-rule in native CSS");
|
|
1111
|
-
parseNativeRuleBody(nestedAtRuleChildren, parsed, [...
|
|
1144
|
+
parseNativeRuleBody(nestedAtRuleChildren, parsed, [...conditionPath, conditionEntry(atRule)], parentSelectorDefinition);
|
|
1112
1145
|
return;
|
|
1113
1146
|
}
|
|
1114
1147
|
if (child.type === "style") {
|
|
1115
|
-
parseNativeStyleRule(child, parsed,
|
|
1148
|
+
parseNativeStyleRule(child, parsed, conditionPath, parentSelectorDefinition);
|
|
1116
1149
|
return;
|
|
1117
1150
|
}
|
|
1118
1151
|
throw new Error("Native CSS rules only accept declarations, @compose, nested selectors, and nested at-rules");
|
|
1119
1152
|
}
|
|
1120
|
-
function parseNativeStyleRule(rule, parsed,
|
|
1153
|
+
function parseNativeStyleRule(rule, parsed, conditionPath = [], parentSelectorDefinition) {
|
|
1121
1154
|
const selectorDefinition = parseNativeSelectorDefinition(rule.value.selectors, parentSelectorDefinition);
|
|
1122
1155
|
selectorDefinition.source = createSelectorSourceReference(parsed, rule) || parentSelectorDefinition?.source;
|
|
1123
|
-
parseStyleDefinitionBody(parsed, selectorDefinition, collectDirectiveStyleRule(rule, parsed),
|
|
1156
|
+
parseStyleDefinitionBody(parsed, selectorDefinition, collectDirectiveStyleRule(rule, parsed), conditionPath, void 0, void 0);
|
|
1124
1157
|
}
|
|
1125
1158
|
function formatKeyframeSelector(selector) {
|
|
1126
1159
|
switch (selector.type) {
|
|
@@ -1234,6 +1267,8 @@ const MANAGED_DYNAMIC_SOURCE_KINDS = /* @__PURE__ */ new Set([
|
|
|
1234
1267
|
"image"
|
|
1235
1268
|
]);
|
|
1236
1269
|
const MANAGED_DYNAMIC_RAW_ANY_SOURCE = "*";
|
|
1270
|
+
const MANAGED_ENUM_PATTERN_TOKEN = /^-?[_a-zA-Z0-9][-_a-zA-Z0-9]*$/;
|
|
1271
|
+
const MANAGED_ENUM_PATTERN_VALUE = /^-?[_a-zA-Z0-9][-_a-zA-Z0-9]*$/;
|
|
1237
1272
|
function parseManagedPatternSegments(pattern) {
|
|
1238
1273
|
const segments = [...pattern.matchAll(/<([^<>]*)>/g)];
|
|
1239
1274
|
if (segments.length !== 1) throw new Error("Managed pattern must contain exactly one <...> segment");
|
|
@@ -1257,15 +1292,31 @@ function parseManagedEnumPatternName(source) {
|
|
|
1257
1292
|
if (!prefix || suffix) throw new Error("Managed enum pattern must use a prefix before <...> and no suffix");
|
|
1258
1293
|
if (!rawValues) throw new Error("Managed enum pattern cannot be empty");
|
|
1259
1294
|
if (rawValues.includes(",")) throw new Error("Managed enum pattern values must use \"|\" separators like text-<left|right>");
|
|
1260
|
-
const
|
|
1261
|
-
if (
|
|
1262
|
-
|
|
1295
|
+
const entries = rawValues.split("|").map((value) => value.trim());
|
|
1296
|
+
if (entries.length < 2 || entries.some((value) => !value)) throw new Error("Managed enum pattern requires at least two values separated by \"|\"");
|
|
1297
|
+
const values = [];
|
|
1298
|
+
const valueMap = {};
|
|
1299
|
+
let hasMappedValue = false;
|
|
1300
|
+
const canonicalValues = [];
|
|
1301
|
+
for (const entry of entries) {
|
|
1302
|
+
const equalsIndex = entry.indexOf("=");
|
|
1303
|
+
const classValue = equalsIndex === -1 ? entry : entry.slice(0, equalsIndex).trim();
|
|
1304
|
+
const emittedValue = equalsIndex === -1 ? classValue : entry.slice(equalsIndex + 1).trim();
|
|
1305
|
+
if (!classValue || !emittedValue || entry.indexOf("=", equalsIndex + 1) !== -1) throw new Error(`Invalid managed enum mapping: ${entry}`);
|
|
1306
|
+
if (!MANAGED_ENUM_PATTERN_TOKEN.test(classValue)) throw new Error(`Invalid managed enum value: ${classValue}`);
|
|
1307
|
+
if (!MANAGED_ENUM_PATTERN_VALUE.test(emittedValue)) throw new Error(`Invalid managed enum mapped value: ${emittedValue}`);
|
|
1308
|
+
values.push(classValue);
|
|
1309
|
+
valueMap[classValue] = emittedValue;
|
|
1310
|
+
if (equalsIndex !== -1) hasMappedValue = true;
|
|
1311
|
+
canonicalValues.push(equalsIndex === -1 ? classValue : `${classValue}=${emittedValue}`);
|
|
1312
|
+
}
|
|
1263
1313
|
return {
|
|
1264
1314
|
kind: "pattern",
|
|
1265
|
-
name: `${prefix}<${
|
|
1315
|
+
name: `${prefix}<${canonicalValues.join("|")}>`,
|
|
1266
1316
|
pattern: {
|
|
1267
1317
|
prefix,
|
|
1268
|
-
values
|
|
1318
|
+
values,
|
|
1319
|
+
...hasMappedValue ? { valueMap } : {}
|
|
1269
1320
|
}
|
|
1270
1321
|
};
|
|
1271
1322
|
}
|
|
@@ -1347,22 +1398,24 @@ function ensureUtilityDefinitionRules(definition) {
|
|
|
1347
1398
|
if (!definition.declarations) return;
|
|
1348
1399
|
const declarations = definition.declarations;
|
|
1349
1400
|
delete definition.declarations;
|
|
1350
|
-
const
|
|
1351
|
-
delete definition.
|
|
1401
|
+
const conditions = definition.conditions;
|
|
1402
|
+
delete definition.conditions;
|
|
1403
|
+
const conditionPath = definition.conditionPath;
|
|
1404
|
+
delete definition.conditionPath;
|
|
1352
1405
|
definition.rules ??= [];
|
|
1353
1406
|
definition.rules.push({
|
|
1354
1407
|
declarations,
|
|
1355
|
-
...
|
|
1408
|
+
...conditionPath?.length ? createConditionPathProperties(conditionPath) : conditions?.length ? { conditions: [...conditions] } : {}
|
|
1356
1409
|
});
|
|
1357
1410
|
}
|
|
1358
|
-
function pushUtilityDefinitionRule(definition, declarations, selector = "&",
|
|
1411
|
+
function pushUtilityDefinitionRule(definition, declarations, selector = "&", conditionPath = []) {
|
|
1359
1412
|
if (!Object.keys(declarations).length) return;
|
|
1360
1413
|
const rule = {
|
|
1361
1414
|
declarations,
|
|
1362
1415
|
...selector !== "&" ? { selector } : {},
|
|
1363
|
-
...
|
|
1416
|
+
...createConditionPathProperties(conditionPath)
|
|
1364
1417
|
};
|
|
1365
|
-
if (!definition.declarations && !definition.rules?.length && !rule.selector && !rule.
|
|
1418
|
+
if (!definition.declarations && !definition.rules?.length && !rule.selector && !rule.conditions && !rule.conditionPath) {
|
|
1366
1419
|
definition.declarations = declarations;
|
|
1367
1420
|
return;
|
|
1368
1421
|
}
|
|
@@ -1370,33 +1423,33 @@ function pushUtilityDefinitionRule(definition, declarations, selector = "&", atR
|
|
|
1370
1423
|
definition.rules ??= [];
|
|
1371
1424
|
definition.rules.push(rule);
|
|
1372
1425
|
}
|
|
1373
|
-
function parseManagedPatternStyleDefinitionBody(parsed, definition, items, directiveName, selectors = ["&"],
|
|
1426
|
+
function parseManagedPatternStyleDefinitionBody(parsed, definition, items, directiveName, selectors = ["&"], conditionPath = []) {
|
|
1374
1427
|
for (const item of items) {
|
|
1375
1428
|
if (item.type === "declarations") {
|
|
1376
|
-
for (const selector of selectors) pushUtilityDefinitionRule(definition, item.declarations, selector,
|
|
1429
|
+
for (const selector of selectors) pushUtilityDefinitionRule(definition, item.declarations, selector, conditionPath);
|
|
1377
1430
|
continue;
|
|
1378
1431
|
}
|
|
1379
1432
|
if (item.type === "compose") throw new CSSDirectiveError("compose-placement", `@compose is not supported inside managed pattern definitions`, item.directiveSource);
|
|
1380
|
-
parseManagedPatternChildRule(item.rule, parsed, definition, directiveName, selectors,
|
|
1433
|
+
parseManagedPatternChildRule(item.rule, parsed, definition, directiveName, selectors, conditionPath);
|
|
1381
1434
|
}
|
|
1382
1435
|
}
|
|
1383
|
-
function parseManagedPatternChildRule(child, parsed, definition, directiveName, selectors = ["&"],
|
|
1436
|
+
function parseManagedPatternChildRule(child, parsed, definition, directiveName, selectors = ["&"], conditionPath = []) {
|
|
1384
1437
|
if (child.type === "layer-block") throw new Error(`Nested @layer blocks are not allowed inside @${directiveName}`);
|
|
1385
1438
|
assertNotSlotRule(child);
|
|
1386
1439
|
const masterVariantBlock = parseMasterVariantBlock(child);
|
|
1387
1440
|
if (masterVariantBlock) {
|
|
1388
|
-
parseManagedPatternStyleDefinitionBody(parsed, definition, collectDirectiveStyleRuleBody(EMPTY_DECLARATION_BLOCK, masterVariantBlock.rules, parsed), directiveName, selectors, [...
|
|
1441
|
+
parseManagedPatternStyleDefinitionBody(parsed, definition, collectDirectiveStyleRuleBody(EMPTY_DECLARATION_BLOCK, masterVariantBlock.rules, parsed), directiveName, selectors, [...conditionPath, variantEntry(masterVariantBlock.token)]);
|
|
1389
1442
|
return;
|
|
1390
1443
|
}
|
|
1391
1444
|
const nestedAtRuleChildren = getNestedAtRuleChildren(child);
|
|
1392
1445
|
if (nestedAtRuleChildren) {
|
|
1393
1446
|
const atRule = formatNestedAtRule(child);
|
|
1394
1447
|
if (!atRule) throw new Error(`Unsupported nested at-rule inside @${directiveName}`);
|
|
1395
|
-
parseManagedPatternStyleDefinitionBody(parsed, definition, collectDirectiveStyleRuleBody(EMPTY_DECLARATION_BLOCK, nestedAtRuleChildren, parsed), directiveName, selectors, [...
|
|
1448
|
+
parseManagedPatternStyleDefinitionBody(parsed, definition, collectDirectiveStyleRuleBody(EMPTY_DECLARATION_BLOCK, nestedAtRuleChildren, parsed), directiveName, selectors, [...conditionPath, conditionEntry(atRule)]);
|
|
1396
1449
|
return;
|
|
1397
1450
|
}
|
|
1398
1451
|
if (child.type === "style") {
|
|
1399
|
-
parseManagedPatternStyleDefinitionBody(parsed, definition, collectDirectiveStyleRule(child, parsed), directiveName, combineStyleSelectorLists(selectors, child.value.selectors),
|
|
1452
|
+
parseManagedPatternStyleDefinitionBody(parsed, definition, collectDirectiveStyleRule(child, parsed), directiveName, combineStyleSelectorLists(selectors, child.value.selectors), conditionPath);
|
|
1400
1453
|
return;
|
|
1401
1454
|
}
|
|
1402
1455
|
const compose = parseComposeRule(child, parsed);
|
|
@@ -1404,14 +1457,14 @@ function parseManagedPatternChildRule(child, parsed, definition, directiveName,
|
|
|
1404
1457
|
if (child.type === "keyframes") throw new Error(`@keyframes is not allowed inside @${directiveName}. Move managed animation definitions to top-level @theme.`);
|
|
1405
1458
|
throw new Error(`Managed pattern definitions only accept declarations, nested selectors, and nested at-rules`);
|
|
1406
1459
|
}
|
|
1407
|
-
function parseManagedPatternDefinitionRule(child, parsed, parsedPattern,
|
|
1460
|
+
function parseManagedPatternDefinitionRule(child, parsed, parsedPattern, conditionPath, layer, directiveName) {
|
|
1408
1461
|
const definition = {
|
|
1409
1462
|
name: parsedPattern.name,
|
|
1410
1463
|
type: parsedPattern.kind === "pattern" ? "pattern" : "dynamic",
|
|
1411
1464
|
layer,
|
|
1412
1465
|
...parsedPattern.kind === "pattern" ? { pattern: parsedPattern.pattern } : { dynamic: parsedPattern.dynamic }
|
|
1413
1466
|
};
|
|
1414
|
-
parseManagedPatternStyleDefinitionBody(parsed, definition, collectDirectiveStyleRule(child, parsed), directiveName, ["&"],
|
|
1467
|
+
parseManagedPatternStyleDefinitionBody(parsed, definition, collectDirectiveStyleRule(child, parsed), directiveName, ["&"], conditionPath);
|
|
1415
1468
|
parsed.manifestInput.utilities ??= [];
|
|
1416
1469
|
parsed.manifestInput.utilities.push(definition);
|
|
1417
1470
|
}
|
|
@@ -1425,18 +1478,18 @@ function containsNativeStyleDirective(rule) {
|
|
|
1425
1478
|
function createManagedDefinitionNameError(rule) {
|
|
1426
1479
|
return /* @__PURE__ */ new Error(`Managed definition names must be bare identifiers: ${formatSelectors(rule.value.selectors)}`);
|
|
1427
1480
|
}
|
|
1428
|
-
function parseManagedDefinitionDirectiveChildRule(child, parsed,
|
|
1481
|
+
function parseManagedDefinitionDirectiveChildRule(child, parsed, conditionPath, layer, directiveName) {
|
|
1429
1482
|
if (child.type === "layer-block") throw new Error(`Nested @layer blocks are not allowed inside @${directiveName}`);
|
|
1430
1483
|
const masterVariantBlock = parseMasterVariantBlock(child);
|
|
1431
1484
|
if (masterVariantBlock) {
|
|
1432
|
-
for (const nestedChild of masterVariantBlock.rules) parseManagedDefinitionDirectiveChildRule(nestedChild, parsed, [...
|
|
1485
|
+
for (const nestedChild of masterVariantBlock.rules) parseManagedDefinitionDirectiveChildRule(nestedChild, parsed, [...conditionPath, variantEntry(masterVariantBlock.token)], layer, directiveName);
|
|
1433
1486
|
return;
|
|
1434
1487
|
}
|
|
1435
1488
|
const nestedAtRuleChildren = getNestedAtRuleChildren(child);
|
|
1436
1489
|
if (nestedAtRuleChildren) {
|
|
1437
1490
|
const atRule = formatNestedAtRule(child);
|
|
1438
1491
|
if (!atRule) throw new Error(`Unsupported nested at-rule inside @${directiveName}`);
|
|
1439
|
-
for (const nestedChild of nestedAtRuleChildren) parseManagedDefinitionDirectiveChildRule(nestedChild, parsed, [...
|
|
1492
|
+
for (const nestedChild of nestedAtRuleChildren) parseManagedDefinitionDirectiveChildRule(nestedChild, parsed, [...conditionPath, conditionEntry(atRule)], layer, directiveName);
|
|
1440
1493
|
return;
|
|
1441
1494
|
}
|
|
1442
1495
|
if (child.type === "nested-declarations") throw new Error(`@${directiveName} only accepts bare managed names and nested at-rules`);
|
|
@@ -1447,11 +1500,11 @@ function parseManagedDefinitionDirectiveChildRule(child, parsed, atRules, layer,
|
|
|
1447
1500
|
const selectorDefinition = parseManagedDefinitionNameSelector(child.value.selectors);
|
|
1448
1501
|
if (!selectorDefinition) throw createManagedDefinitionNameError(child);
|
|
1449
1502
|
if (parsedPattern) {
|
|
1450
|
-
parseManagedPatternDefinitionRule(child, parsed, parsedPattern,
|
|
1503
|
+
parseManagedPatternDefinitionRule(child, parsed, parsedPattern, conditionPath, layer, directiveName);
|
|
1451
1504
|
return;
|
|
1452
1505
|
}
|
|
1453
1506
|
selectorDefinition.source = selectorSource;
|
|
1454
|
-
parseStyleDefinitionBody(parsed, selectorDefinition, collectDirectiveStyleRule(child, parsed),
|
|
1507
|
+
parseStyleDefinitionBody(parsed, selectorDefinition, collectDirectiveStyleRule(child, parsed), conditionPath, layer);
|
|
1455
1508
|
return;
|
|
1456
1509
|
}
|
|
1457
1510
|
if ((child.type === "unknown" || child.type === "custom") && child.value?.name === "compose") throw createComposePlacementError(parsed);
|
|
@@ -1563,14 +1616,14 @@ function compileCSS(source, options = {}) {
|
|
|
1563
1616
|
}
|
|
1564
1617
|
const masterVariantBlock = parseMasterVariantBlock(rule);
|
|
1565
1618
|
if (masterVariantBlock) {
|
|
1566
|
-
parseNativeRuleBody(masterVariantBlock.rules, parsed, [
|
|
1619
|
+
parseNativeRuleBody(masterVariantBlock.rules, parsed, [variantEntry(masterVariantBlock.token)]);
|
|
1567
1620
|
return [];
|
|
1568
1621
|
}
|
|
1569
1622
|
const nestedAtRuleChildren = getNestedAtRuleChildren(rule);
|
|
1570
1623
|
if (nestedAtRuleChildren && containsNativeStyleDirective(rule)) {
|
|
1571
1624
|
const atRule = formatNestedAtRule(rule);
|
|
1572
1625
|
if (!atRule) throw new Error("Unsupported nested at-rule in native CSS");
|
|
1573
|
-
parseNativeRuleBody(nestedAtRuleChildren, parsed, [atRule]);
|
|
1626
|
+
parseNativeRuleBody(nestedAtRuleChildren, parsed, [conditionEntry(atRule)]);
|
|
1574
1627
|
return [];
|
|
1575
1628
|
}
|
|
1576
1629
|
if (rule.type === "style" && containsNativeStyleDirective(rule)) {
|
|
@@ -1608,7 +1661,7 @@ function compileCSS(source, options = {}) {
|
|
|
1608
1661
|
let remainingCSS = "";
|
|
1609
1662
|
if (options.preserveNativeCSS !== false) {
|
|
1610
1663
|
const filteredCode = filterNativeCSS(transformed.code, filename, parsed, classFilter);
|
|
1611
|
-
remainingCSS = decodeCSS(classFilter ? pruneEmptyRuleBlocks(filteredCode, filename) : filteredCode).trim();
|
|
1664
|
+
remainingCSS = normalizeStylesheetValue(decodeCSS(classFilter ? pruneEmptyRuleBlocks(filteredCode, filename) : filteredCode).trim()).value;
|
|
1612
1665
|
}
|
|
1613
1666
|
return {
|
|
1614
1667
|
manifestInput: parsed.manifestInput,
|
package/dist/css-transform.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { MasterCSSManifest } from "@master/css-schema/manifest";
|
|
2
2
|
import { CSSReferenceStatement, CSSReferenceStatement as CSSReferenceStatement$1, CompileCSSFileOptions, CompileCSSFileOptions as CompileCSSFileOptions$1, CompileCSSOptions, CompileCSSOptions as CompileCSSOptions$1, CompileCSSResult, CompileCSSResult as CompileCSSResult$1, ResolvedCSSImportGraph, ResolvedCSSImportGraph as ResolvedCSSImportGraph$1, StandaloneCSSDirectiveStatement, StandaloneMasterDirectiveStatement } from "./core.js";
|
|
3
3
|
export * from "./core.js";
|
|
4
|
-
|
|
5
4
|
//#region src/index.d.ts
|
|
6
5
|
interface InspectCSSResult {
|
|
7
6
|
hasMasterEntryDirective: boolean;
|
package/dist/lexer/imports.d.ts
CHANGED
package/dist/lexer/source.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { CSSDirectiveManifestInput, CSSDirectiveResult } 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/lower-css-directives.d.ts
|
|
6
5
|
interface LowerCSSDirectivesOptions {
|
|
7
6
|
baseManifest?: MasterCSSManifest;
|