@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
package/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# @master/css-engine
|
|
2
|
+
|
|
3
|
+
The manifest-driven Master CSS engine.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @master/css-engine
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Responsibility
|
|
12
|
+
|
|
13
|
+
`@master/css-engine` executes `MasterCSSManifest` values. It owns class matching, value parsing, selector and at-rule parsing/generation, variable and animation insertion, cascade layers, rule priority sorting, hydration manifest generation, CSS text emission, and built-in key/namespace registries.
|
|
14
|
+
|
|
15
|
+
This package does not discover project files, resolve CSS imports, compile CSS directives, or integrate with frameworks.
|
|
16
|
+
|
|
17
|
+
## API
|
|
18
|
+
|
|
19
|
+
### `MasterCSS`
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { MasterCSS } from '@master/css-engine'
|
|
23
|
+
|
|
24
|
+
const css = MasterCSS.create({ manifest })
|
|
25
|
+
|
|
26
|
+
css.add('text:center', 'font:semibold')
|
|
27
|
+
console.log(css.text)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
| API | Description |
|
|
31
|
+
| --- | --- |
|
|
32
|
+
| `MasterCSS.create({ manifest, emittedGlobals })` | Creates a `MasterCSS` instance. |
|
|
33
|
+
| `css.add(...classNames)` | Adds class names and generated rules. |
|
|
34
|
+
| `css.remove(...classNames)` | Removes class names and unused rules. |
|
|
35
|
+
| `css.createRule(className)` | Creates one generated rule without inserting it. |
|
|
36
|
+
| `css.createRules(className)` | Creates all generated rule branches without inserting them. |
|
|
37
|
+
| `css.refresh(manifest?)` | Refreshes with a compiled manifest. |
|
|
38
|
+
| `css.reset()` | Clears rules and state. |
|
|
39
|
+
| `css.text` | Generated CSS text. |
|
|
40
|
+
|
|
41
|
+
### Compiler helpers
|
|
42
|
+
|
|
43
|
+
`@master/css-engine/compiler` exposes parse, generate, inspect, and built-in registry helpers used by the compiler, language tooling, docs, and tests.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import {
|
|
47
|
+
builtinKeyAliases,
|
|
48
|
+
builtinNativeValueNamespaces,
|
|
49
|
+
compareRulePriority,
|
|
50
|
+
} from '@master/css-engine/compiler'
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Related packages
|
|
54
|
+
|
|
55
|
+
- `@master/css` is the public facade over this package and the default preset.
|
|
56
|
+
- `@master/css-compiler` lowers CSS directives into manifests.
|
|
57
|
+
- `@master/css-runtime` runs the engine against live browser DOM roots.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import MasterCSS from './core';
|
|
2
|
+
import type { MasterCSSManifestAnimations } from '@master/css-schema/manifest';
|
|
3
|
+
export default class AnimationRule {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly keyframes: MasterCSSManifestAnimations[string];
|
|
6
|
+
readonly css: MasterCSS;
|
|
7
|
+
native?: CSSKeyframeRule;
|
|
8
|
+
variableNames?: Set<string>;
|
|
9
|
+
constructor(name: string, keyframes: MasterCSSManifestAnimations[string], css: MasterCSS);
|
|
10
|
+
get key(): string;
|
|
11
|
+
get text(): string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import collectVariableNames from './utils/collect-variable-names.mjs';
|
|
2
|
+
|
|
3
|
+
class AnimationRule {
|
|
4
|
+
name;
|
|
5
|
+
keyframes;
|
|
6
|
+
css;
|
|
7
|
+
native;
|
|
8
|
+
variableNames;
|
|
9
|
+
constructor(name, keyframes, css){
|
|
10
|
+
this.name = name;
|
|
11
|
+
this.keyframes = keyframes;
|
|
12
|
+
this.css = css;
|
|
13
|
+
for (const declarations of Object.values(keyframes)){
|
|
14
|
+
const variableNames = collectVariableNames(declarations, css.variables);
|
|
15
|
+
if (!variableNames) continue;
|
|
16
|
+
for (const variableName of variableNames){
|
|
17
|
+
if (this.variableNames) {
|
|
18
|
+
this.variableNames.add(variableName);
|
|
19
|
+
} else {
|
|
20
|
+
this.variableNames = new Set([
|
|
21
|
+
variableName
|
|
22
|
+
]);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
get key() {
|
|
28
|
+
return this.name;
|
|
29
|
+
}
|
|
30
|
+
get text() {
|
|
31
|
+
return `@keyframes ${this.name}{` + Object.entries(this.keyframes).reduce((acc, [key, variables])=>{
|
|
32
|
+
const variableText = Object.entries(variables).map(([name, value])=>`${name}:${value}`).join(';');
|
|
33
|
+
return acc + `${key}{${variableText}}`;
|
|
34
|
+
}, '') + '}';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { AnimationRule as default };
|
package/dist/common.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { MasterCSSManifestAtIdentifier } from '@master/css-schema/manifest';
|
|
2
|
+
export declare const VALUE_DELIMITERS: {
|
|
3
|
+
'(': string;
|
|
4
|
+
'\'': string;
|
|
5
|
+
'"': string;
|
|
6
|
+
'{': string;
|
|
7
|
+
};
|
|
8
|
+
export declare const BASE_UNIT_REGEX: RegExp;
|
|
9
|
+
export declare const SELECTOR_SIGNS: string[];
|
|
10
|
+
export declare const SELECTOR_COMBINATORS: string[];
|
|
11
|
+
export declare const QUERY_COMPARISON_OPERATORS: string[];
|
|
12
|
+
export declare const QUERY_LOGICAL_OPERATORS: string[];
|
|
13
|
+
export declare const SEPARATOR_SIGNS: string[];
|
|
14
|
+
export declare const DELIMITER_SIGN = "|";
|
|
15
|
+
export declare const SEPARATOR_SIGN = ",";
|
|
16
|
+
export declare const AT_SIGN = "@";
|
|
17
|
+
export declare const VALUE_UNITS: ("%" | "cm" | "mm" | "q" | "in" | "pt" | "pc" | "px" | "em" | "rem" | "ex" | "rex" | "cap" | "rcap" | "ch" | "rch" | "ic" | "ric" | "lh" | "rlh" | "vw" | "svw" | "lvw" | "dvw" | "vh" | "svh" | "lvh" | "dvh" | "vi" | "svi" | "lvi" | "dvi" | "vb" | "svb" | "lvb" | "dvb" | "vmin" | "svmin" | "lvmin" | "dvmin" | "vmax" | "svmax" | "lvmax" | "dvmax" | "cqw" | "cqh" | "cqi" | "cqb" | "cqmin" | "cqmax" | "deg" | "grad" | "rad" | "turn" | "s" | "ms" | "hz" | "khz" | "dpi" | "dpcm" | "dppx" | "x" | "fr" | "db" | "st")[];
|
|
18
|
+
export declare const UNIT_REGEX: RegExp;
|
|
19
|
+
export declare const CLASS_ATTRIBUTES: string[];
|
|
20
|
+
export declare const CLASS_DECLARATIONS: never[];
|
|
21
|
+
export declare const CLASS_FUNCTIONS: string[];
|
|
22
|
+
export declare const MATCH_NAME_BOUNDARY: Set<string>;
|
|
23
|
+
export declare const AT_COMPARISON_OPERATORS: string[];
|
|
24
|
+
export declare const AT_LOGICAL_OPERATORS: {
|
|
25
|
+
'&': string;
|
|
26
|
+
'!': string;
|
|
27
|
+
not: string;
|
|
28
|
+
and: string;
|
|
29
|
+
or: string;
|
|
30
|
+
only: string;
|
|
31
|
+
',': string;
|
|
32
|
+
};
|
|
33
|
+
export declare const AT_IDENTIFIERS: MasterCSSManifestAtIdentifier[];
|
|
34
|
+
export declare const COMPARISION_OPERATORS: string[];
|
|
35
|
+
export declare const AT_COMPARABLE_FEATURES: string[];
|
|
36
|
+
export declare const AT_FEATURE_ALIASES: {
|
|
37
|
+
readonly w: "width";
|
|
38
|
+
readonly h: "height";
|
|
39
|
+
};
|
|
40
|
+
export declare const __UNSORTED__ = "__UNSORTED__";
|
package/dist/common.mjs
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { MASTER_CSS_VALUE_UNITS, MASTER_CSS_VALUE_UNIT_PATTERN } from '@master/css-lexer';
|
|
2
|
+
|
|
3
|
+
const VALUE_DELIMITERS = {
|
|
4
|
+
'(': ')',
|
|
5
|
+
'\'': '\'',
|
|
6
|
+
'"': '"',
|
|
7
|
+
'{': '}'
|
|
8
|
+
};
|
|
9
|
+
const BASE_UNIT_REGEX = /^([+-]?(?:\d+(?:\.?\d+)?|\.\d+))x$/m // 1x, 1.1x, -1x, -.1x
|
|
10
|
+
;
|
|
11
|
+
const SELECTOR_SIGNS = [
|
|
12
|
+
':',
|
|
13
|
+
'_',
|
|
14
|
+
'>',
|
|
15
|
+
'+',
|
|
16
|
+
'~'
|
|
17
|
+
];
|
|
18
|
+
const SELECTOR_COMBINATORS = [
|
|
19
|
+
'_',
|
|
20
|
+
'>',
|
|
21
|
+
'+',
|
|
22
|
+
'~'
|
|
23
|
+
];
|
|
24
|
+
const QUERY_COMPARISON_OPERATORS = [
|
|
25
|
+
'>',
|
|
26
|
+
'<',
|
|
27
|
+
'='
|
|
28
|
+
];
|
|
29
|
+
const QUERY_LOGICAL_OPERATORS = [
|
|
30
|
+
'&'
|
|
31
|
+
];
|
|
32
|
+
const SEPARATOR_SIGNS = [
|
|
33
|
+
',',
|
|
34
|
+
'|'
|
|
35
|
+
];
|
|
36
|
+
const DELIMITER_SIGN = '|';
|
|
37
|
+
const SEPARATOR_SIGN = ',';
|
|
38
|
+
const AT_SIGN = '@';
|
|
39
|
+
const VALUE_UNITS = [
|
|
40
|
+
...MASTER_CSS_VALUE_UNITS
|
|
41
|
+
];
|
|
42
|
+
const UNIT_REGEX = new RegExp(`^([+-.]?\\d+(?:\\.?\\d+)?)(${MASTER_CSS_VALUE_UNIT_PATTERN})?$`);
|
|
43
|
+
const CLASS_ATTRIBUTES = [
|
|
44
|
+
'class',
|
|
45
|
+
'className'
|
|
46
|
+
];
|
|
47
|
+
const CLASS_DECLARATIONS = [];
|
|
48
|
+
const CLASS_FUNCTIONS = [
|
|
49
|
+
'clsx',
|
|
50
|
+
'cva',
|
|
51
|
+
'ctl',
|
|
52
|
+
'cv',
|
|
53
|
+
'class',
|
|
54
|
+
'classnames',
|
|
55
|
+
'classVariant',
|
|
56
|
+
'styled(?:\\s+)?(?:\\.\\w+)?',
|
|
57
|
+
'classList(?:\\s+)?\\.(?:add|remove|toggle|replace)'
|
|
58
|
+
];
|
|
59
|
+
const MATCH_NAME_BOUNDARY = new Set([
|
|
60
|
+
'!',
|
|
61
|
+
'*',
|
|
62
|
+
'>',
|
|
63
|
+
'+',
|
|
64
|
+
'~',
|
|
65
|
+
':',
|
|
66
|
+
'[',
|
|
67
|
+
'@',
|
|
68
|
+
'_',
|
|
69
|
+
'.'
|
|
70
|
+
]);
|
|
71
|
+
const AT_COMPARISON_OPERATORS = [
|
|
72
|
+
'>=',
|
|
73
|
+
'<=',
|
|
74
|
+
'>',
|
|
75
|
+
'<',
|
|
76
|
+
'='
|
|
77
|
+
];
|
|
78
|
+
const AT_LOGICAL_OPERATORS = {
|
|
79
|
+
'&': 'and',
|
|
80
|
+
'!': 'not',
|
|
81
|
+
// native
|
|
82
|
+
'not': 'not',
|
|
83
|
+
'and': 'and',
|
|
84
|
+
'or': 'or',
|
|
85
|
+
'only': 'only',
|
|
86
|
+
',': 'or'
|
|
87
|
+
};
|
|
88
|
+
// the order is intentional and should not be changed
|
|
89
|
+
const AT_IDENTIFIERS = [
|
|
90
|
+
'container',
|
|
91
|
+
'starting-style',
|
|
92
|
+
'supports',
|
|
93
|
+
'media',
|
|
94
|
+
'layer'
|
|
95
|
+
];
|
|
96
|
+
const COMPARISION_OPERATORS = [
|
|
97
|
+
'>=',
|
|
98
|
+
'<=',
|
|
99
|
+
'>',
|
|
100
|
+
'<',
|
|
101
|
+
'='
|
|
102
|
+
];
|
|
103
|
+
const AT_COMPARABLE_FEATURES = [
|
|
104
|
+
'width',
|
|
105
|
+
'height',
|
|
106
|
+
'resolution'
|
|
107
|
+
];
|
|
108
|
+
const AT_FEATURE_ALIASES = {
|
|
109
|
+
w: 'width',
|
|
110
|
+
h: 'height'
|
|
111
|
+
};
|
|
112
|
+
const __UNSORTED__ = '__UNSORTED__';
|
|
113
|
+
|
|
114
|
+
export { AT_COMPARABLE_FEATURES, AT_COMPARISON_OPERATORS, AT_FEATURE_ALIASES, AT_IDENTIFIERS, AT_LOGICAL_OPERATORS, AT_SIGN, BASE_UNIT_REGEX, CLASS_ATTRIBUTES, CLASS_DECLARATIONS, CLASS_FUNCTIONS, COMPARISION_OPERATORS, DELIMITER_SIGN, MATCH_NAME_BOUNDARY, QUERY_COMPARISON_OPERATORS, QUERY_LOGICAL_OPERATORS, SELECTOR_COMBINATORS, SELECTOR_SIGNS, SEPARATOR_SIGN, SEPARATOR_SIGNS, UNIT_REGEX, VALUE_DELIMITERS, VALUE_UNITS, __UNSORTED__ };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Variable } from '@master/css-schema/css-syntax';
|
|
2
|
+
import type { MasterCSSManifest, MasterCSSManifestAnimations, MasterCSSManifestSettings, MasterCSSManifestUtility, MasterCSSManifestVariantBranch, MasterCSSManifestVariantToken } from '@master/css-schema/manifest';
|
|
3
|
+
import type { AtRule } from './utils/parse-at';
|
|
4
|
+
import type { SelectorNode } from './utils/parse-selector';
|
|
5
|
+
export type CompiledUtility = Omit<MasterCSSManifestUtility, 'emit' | 'name' | 'order'> & {
|
|
6
|
+
name: string;
|
|
7
|
+
order: number;
|
|
8
|
+
emit: MasterCSSManifestUtility['emit'] | {
|
|
9
|
+
type: 'group';
|
|
10
|
+
};
|
|
11
|
+
variables?: Map<string, Variable>;
|
|
12
|
+
};
|
|
13
|
+
export type EngineSettings = MasterCSSManifestSettings & {
|
|
14
|
+
rootSize: number;
|
|
15
|
+
baseUnit: number;
|
|
16
|
+
defaultMode: NonNullable<MasterCSSManifestSettings['defaultMode']>;
|
|
17
|
+
modeTrigger: NonNullable<MasterCSSManifestSettings['modeTrigger']>;
|
|
18
|
+
modes: string[];
|
|
19
|
+
};
|
|
20
|
+
export interface CompiledManifest {
|
|
21
|
+
manifest: MasterCSSManifest;
|
|
22
|
+
settings: EngineSettings;
|
|
23
|
+
definedUtilities: CompiledUtility[];
|
|
24
|
+
variableMatcherUtilities: CompiledUtility[];
|
|
25
|
+
valueMatcherUtilities: CompiledUtility[];
|
|
26
|
+
keyMatcherUtilities: CompiledUtility[];
|
|
27
|
+
patternMatcherUtilities: CompiledUtility[];
|
|
28
|
+
arbitraryMatcherUtilities: CompiledUtility[];
|
|
29
|
+
variableMatcherIndex: Map<string, CompiledUtility[]>;
|
|
30
|
+
valueMatcherIndex: Map<string, CompiledUtility[]>;
|
|
31
|
+
keyMatcherIndex: Map<string, CompiledUtility[]>;
|
|
32
|
+
patternMatcherIndex?: Map<string, CompiledUtility[]>;
|
|
33
|
+
arbitraryStaticMatcherIndex?: Map<string, CompiledUtility[]>;
|
|
34
|
+
selectors: Map<string, SelectorNode[]>;
|
|
35
|
+
variables: Map<string, Variable>;
|
|
36
|
+
modes: string[];
|
|
37
|
+
atRules: Map<string, AtRule>;
|
|
38
|
+
variants: Map<MasterCSSManifestVariantToken, MasterCSSManifestVariantBranch[]>;
|
|
39
|
+
breakpointAtRules: Map<string, AtRule>;
|
|
40
|
+
containerAtRules: Map<string, AtRule>;
|
|
41
|
+
animations: Map<string, MasterCSSManifestAnimations[string]>;
|
|
42
|
+
nativeDeclarationFastPathBlockedProperties: Set<string>;
|
|
43
|
+
nativeValueNamespaceUtilities: Map<string, CompiledUtility>;
|
|
44
|
+
keyAliases: Map<string, string>;
|
|
45
|
+
}
|
|
46
|
+
export declare function isPureNativeDeclarationUtilityDefinition(utility: CompiledUtility): utility is CompiledUtility & {
|
|
47
|
+
emit: {
|
|
48
|
+
type: 'property';
|
|
49
|
+
property: string;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export declare function cloneCompiledSettings(settings: EngineSettings): EngineSettings;
|
|
53
|
+
export declare function compileManifest(manifest: MasterCSSManifest): CompiledManifest;
|
|
54
|
+
export declare function getCompiledManifest(manifest: MasterCSSManifest): CompiledManifest;
|