@master/css-compiler 2.0.0-beta.99 → 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 +34 -133
- package/dist/browser.d.ts +22 -0
- package/dist/browser.mjs +47 -0
- package/dist/core.d.ts +48 -0
- package/dist/core.mjs +2019 -0
- package/dist/css-transform.d.ts +6 -0
- package/dist/css-transform.mjs +18 -0
- package/dist/index.d.ts +46 -3
- package/dist/index.mjs +394 -10
- package/dist/lexer/imports.d.ts +13 -0
- package/dist/lexer/imports.mjs +44 -0
- package/dist/lexer/source.d.ts +3 -0
- package/dist/lexer/source.mjs +9 -0
- package/dist/lexer/standalone-master.d.ts +21 -0
- package/dist/lexer/standalone-master.mjs +233 -0
- package/dist/lower-css-directives.d.ts +16 -0
- package/dist/lower-css-directives.mjs +969 -0
- package/dist/master-css-manifest.d.ts +14 -0
- package/dist/master-css-manifest.mjs +760 -0
- package/dist/native-declaration.d.ts +2 -0
- package/dist/native-declaration.mjs +25 -0
- package/dist/utils/selectors.d.ts +3 -0
- package/dist/utils/selectors.mjs +55 -0
- package/dist/utils/unquote.d.ts +1 -0
- package/dist/utils/unquote.mjs +10 -0
- package/dist/utils/wrap-at-rules.d.ts +1 -0
- package/dist/utils/wrap-at-rules.mjs +10 -0
- package/package.json +1 -1
- package/dist/compiler.d.ts +0 -19
- package/dist/extract.d.ts +0 -3
- package/dist/index.cjs +0 -10
- package/dist/options/index.d.ts +0 -17
package/README.md
CHANGED
|
@@ -1,156 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/33840671/201701649-3bb7d698-abec-4d5f-ac30-ccc4d7bafcd4.svg">
|
|
8
|
-
<source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/33840671/201703010-77bf2373-9899-40cc-98f5-30cf9b546941.svg">
|
|
9
|
-
<img alt="Master CSS" src="https://user-images.githubusercontent.com/33840671/201703010-77bf2373-9899-40cc-98f5-30cf9b546941.svg" width="100%">
|
|
10
|
-
</picture>
|
|
11
|
-
</a>
|
|
12
|
-
</p>
|
|
13
|
-
<p align="center">The ahead-of-time compiler of Master CSS</p>
|
|
14
|
-
|
|
15
|
-
<p align="center">
|
|
16
|
-
<a aria-label="overview" href="https://github.com/master-co/css/tree/beta">
|
|
17
|
-
<picture>
|
|
18
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/badge/%E2%AC%85%20back-%20?color=212022&style=for-the-badge">
|
|
19
|
-
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/badge/%E2%AC%85%20back-%20?color=f6f7f8&style=for-the-badge">
|
|
20
|
-
<img alt="NPM Version" src="https://img.shields.io/badge/%E2%AC%85%20back-%20?color=f6f7f8&style=for-the-badge">
|
|
21
|
-
</picture>
|
|
22
|
-
</a>
|
|
23
|
-
<a aria-label="GitHub release (latest by date including pre-releases)" href="https://github.com/master-co/css/releases">
|
|
24
|
-
<picture>
|
|
25
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/v/release/master-co/css?include_prereleases&color=212022&label=&style=for-the-badge&logo=github&logoColor=fff">
|
|
26
|
-
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/github/v/release/master-co/css?include_prereleases&color=f6f7f8&label=&style=for-the-badge&logo=github&logoColor=%23000">
|
|
27
|
-
<img alt="NPM Version" src="https://img.shields.io/github/v/release/master-co/css?include_prereleases&color=f6f7f8&label=&style=for-the-badge&logo=github">
|
|
28
|
-
</picture>
|
|
29
|
-
</a>
|
|
30
|
-
<a aria-label="NPM Package" href="https://www.npmjs.com/package/@master/css-compiler">
|
|
31
|
-
<picture>
|
|
32
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/dm/@master/css-compiler?color=212022&label=%20&logo=npm&style=for-the-badge">
|
|
33
|
-
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/npm/dm/@master/css-compiler?color=f6f7f8&label=%20&logo=npm&style=for-the-badge">
|
|
34
|
-
<img alt="NPM package ( download / month )" src="https://img.shields.io/npm/dm/@master/css-compiler?color=f6f7f8&label=%20&logo=npm&style=for-the-badge">
|
|
35
|
-
</picture>
|
|
36
|
-
</a>
|
|
37
|
-
<a aria-label="Discord Community" href="https://discord.gg/sZNKpAAAw6">
|
|
38
|
-
<picture>
|
|
39
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/discord/917780624314613760?color=212022&label=%20&logo=discord&style=for-the-badge">
|
|
40
|
-
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/discord/917780624314613760?color=f6f7f8&label=%20&logo=discord&style=for-the-badge">
|
|
41
|
-
<img alt="Discord online" src="https://img.shields.io/discord/917780624314613760?color=f6f7f8&label=%20&logo=discord&style=for-the-badge">
|
|
42
|
-
</picture>
|
|
43
|
-
</a>
|
|
44
|
-
<a aria-label="Follow @mastercorg" href="https://twitter.com/mastercorg">
|
|
45
|
-
<picture>
|
|
46
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/static/v1?label=%20&message=twitter&color=212022&logo=twitter&style=for-the-badge">
|
|
47
|
-
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/static/v1?label=%20&message=twitter&color=f6f7f8&logo=twitter&style=for-the-badge">
|
|
48
|
-
<img alt="Follow @mastercorg" src="https://img.shields.io/static/v1?label=%20&message=twitter&color=f6f7f8&logo=twitter&style=for-the-badge">
|
|
49
|
-
</picture>
|
|
50
|
-
</a>
|
|
51
|
-
<a aria-label="Github Actions" href="https://github.com/1aron/repo/actions/workflows/release.yml">
|
|
52
|
-
<picture>
|
|
53
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/actions/workflow/status/master-co/css/release.yml?branch=beta&label=%20&message=twitter&color=212022&logo=githubactions&style=for-the-badge">
|
|
54
|
-
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/github/actions/workflow/status/master-co/css/release.yml?branch=beta&label=%20&message=twitter&color=f6f7f8&logo=githubactions&style=for-the-badge&logoColor=%23000">
|
|
55
|
-
<img alt="Github release actions" src="https://img.shields.io/github/actions/workflow/status/master-co/css/release.yml?branch=beta&label=%20&message=twitter&color=f6f7f8&logo=githubactions&style=for-the-badge&logoColor=%23000">
|
|
56
|
-
</picture>
|
|
57
|
-
</a>
|
|
58
|
-
</p>
|
|
59
|
-
|
|
60
|
-
</div>
|
|
61
|
-
|
|
62
|
-
## Usage
|
|
1
|
+
# @master/css-compiler
|
|
2
|
+
|
|
3
|
+
Compile Master CSS stylesheet directives into manifest data, native CSS, and directive metadata.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
63
7
|
```bash
|
|
64
8
|
npm install @master/css-compiler
|
|
65
9
|
```
|
|
66
10
|
|
|
67
|
-
|
|
68
|
-
const compiler = await new MasterCSSCompiler().init()
|
|
69
|
-
```
|
|
11
|
+
## Responsibility
|
|
70
12
|
|
|
71
|
-
|
|
72
|
-
```ts
|
|
73
|
-
{
|
|
74
|
-
// specify virtual CSS module id (e.g. virtual:master.css)
|
|
75
|
-
module: 'master.css',
|
|
76
|
-
// specify config file path or set `Config`
|
|
77
|
-
config: 'master.css.{ts,js,mjs,cjs}',
|
|
78
|
-
// forcibly specify sources for scanning, not excluded by `options.exclude`
|
|
79
|
-
sources: [],
|
|
80
|
-
// specify sources for scanning
|
|
81
|
-
include: ['**/*.{html,js,jsx,ts,tsx,svelte,astro,vue,md,mdx,pug,php}'],
|
|
82
|
-
// specify sources to exclude
|
|
83
|
-
exclude: [
|
|
84
|
-
'**/node_modules/**',
|
|
85
|
-
'**/*.d.ts',
|
|
86
|
-
'**/*.test.*',
|
|
87
|
-
'node_modules',
|
|
88
|
-
'master.css.{js,ts,mjs,cjs}',
|
|
89
|
-
'dist',
|
|
90
|
-
'out',
|
|
91
|
-
'README.md'
|
|
92
|
-
],
|
|
93
|
-
// whitelist of class names for unpredictable dynamics
|
|
94
|
-
fixedClasses: [],
|
|
95
|
-
// blacklist of class names to exclude accidentally captured
|
|
96
|
-
ignoredClasses: [], // or RegExp[]
|
|
97
|
-
cwd: process.cwd()
|
|
98
|
-
}
|
|
99
|
-
```
|
|
13
|
+
`@master/css-compiler` is the CSS source compiler for Master CSS. It parses CSS manifest directives such as `@settings`, `@theme`, `@custom-variant`, `@defaults`, `@components`, `@utilities`, local `@compose`, top-level extraction directives, native CSS, and CSS import graphs.
|
|
100
14
|
|
|
101
|
-
|
|
15
|
+
The compiler delegates class semantics and rule generation to `@master/css-engine`; project entry discovery belongs to `@master/css-project`.
|
|
102
16
|
|
|
103
|
-
|
|
104
|
-
// Initialize the compiler and MasterCSS
|
|
105
|
-
init(): this
|
|
106
|
-
```
|
|
17
|
+
## API
|
|
107
18
|
|
|
108
|
-
|
|
109
|
-
// Scan sources, extract class names, and generate CSS rules
|
|
110
|
-
compile()
|
|
111
|
-
```
|
|
19
|
+
### Root entry
|
|
112
20
|
|
|
113
|
-
|
|
114
|
-
// Extract potential class names from the given file content
|
|
115
|
-
extract(name: string, content: string): string[]
|
|
116
|
-
```
|
|
21
|
+
Use the root entry in Node environments when CSS imports and filesystem dependencies should be resolved.
|
|
117
22
|
|
|
118
23
|
```ts
|
|
119
|
-
|
|
120
|
-
|
|
24
|
+
import {
|
|
25
|
+
compileCSS,
|
|
26
|
+
compileCSSFile,
|
|
27
|
+
compileCSSManifest,
|
|
28
|
+
compileCSSManifestFile,
|
|
29
|
+
compileProjectManifest,
|
|
30
|
+
} from '@master/css-compiler'
|
|
121
31
|
```
|
|
122
32
|
|
|
123
|
-
|
|
124
|
-
// Read file source paths by `options.include` and `options.exclude`
|
|
125
|
-
get sources(): string[]
|
|
126
|
-
```
|
|
33
|
+
Common flows:
|
|
127
34
|
|
|
128
35
|
```ts
|
|
129
|
-
|
|
130
|
-
|
|
36
|
+
const result = compileCSSManifest('@theme { --color-primary: #4f46e5; }')
|
|
37
|
+
const fileResult = await compileCSSManifestFile('/project/src/index.css')
|
|
38
|
+
const projectResult = await compileProjectManifest(['/project/src/index.css'])
|
|
131
39
|
```
|
|
132
40
|
|
|
133
|
-
|
|
134
|
-
// Read user config file by `options.config`
|
|
135
|
-
readConfig(): Config
|
|
136
|
-
```
|
|
41
|
+
Compiler results include the compiled manifest, dependency paths, warnings, native CSS, and directive metadata used by build integrations.
|
|
137
42
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
```
|
|
43
|
+
### Browser entry
|
|
44
|
+
|
|
45
|
+
Use `@master/css-compiler/browser` when CSS import resolution is not needed.
|
|
142
46
|
|
|
143
47
|
```ts
|
|
144
|
-
|
|
145
|
-
get resolvedConfigPath(): string
|
|
48
|
+
import { compileCSSManifest } from '@master/css-compiler/browser'
|
|
146
49
|
```
|
|
147
50
|
|
|
148
|
-
|
|
51
|
+
The browser compiler rejects `@reference` directives because they require filesystem resolution.
|
|
149
52
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
```
|
|
53
|
+
## Related packages
|
|
54
|
+
|
|
55
|
+
- `@master/css-engine` executes compiled manifests.
|
|
56
|
+
- `@master/css-project` discovers and loads project CSS manifest entries.
|
|
57
|
+
- `@master/css-stylesheet` composes stylesheet entries for static rendering.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import init from 'lightningcss-wasm';
|
|
2
|
+
import type { MasterCSSManifest } from '@master/css-schema/manifest';
|
|
3
|
+
import { type CompileCSSOptions, type CompileCSSResult } from './core';
|
|
4
|
+
export type * from './core';
|
|
5
|
+
export type CompileCSSManifestSourceOptions = CompileCSSOptions & {
|
|
6
|
+
baseManifest?: MasterCSSManifest;
|
|
7
|
+
};
|
|
8
|
+
export interface CompileCSSManifestResult extends Omit<CompileCSSResult, 'manifestInput'> {
|
|
9
|
+
manifest: MasterCSSManifest;
|
|
10
|
+
directives: CompileCSSResult;
|
|
11
|
+
}
|
|
12
|
+
export declare function initCSSCompiler(input?: Parameters<typeof init>[0]): Promise<void>;
|
|
13
|
+
export declare function compileCSS(source: string, options?: CompileCSSOptions): Promise<CompileCSSResult>;
|
|
14
|
+
export declare function compileCSSManifest(source: string, options?: CompileCSSManifestSourceOptions): Promise<CompileCSSManifestResult>;
|
|
15
|
+
export declare function parseDirectives(source: string, options?: CompileCSSOptions): Promise<{
|
|
16
|
+
styleDefinitions?: import("~/packages/schema/src/css-directives").CSSDirectiveStyleDefinition[] | undefined;
|
|
17
|
+
manifestInput: import("~/packages/schema/src/css-directives").CSSDirectiveManifestInput;
|
|
18
|
+
extractionPolicy: import("~/packages/schema/src/css-directives").CSSDirectiveExtractionPolicy;
|
|
19
|
+
classNames: string[];
|
|
20
|
+
nativeClassNames: string[];
|
|
21
|
+
warnings: string[];
|
|
22
|
+
}>;
|
package/dist/browser.mjs
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import init, { transform } from 'lightningcss-wasm';
|
|
2
|
+
import { compileCSS as compileCSS$1, parseDirectives as parseDirectives$1 } from './core.mjs';
|
|
3
|
+
import lowerCSSDirectives from './lower-css-directives.mjs';
|
|
4
|
+
import { setCSSTransform } from './css-transform.mjs';
|
|
5
|
+
|
|
6
|
+
let initPromise;
|
|
7
|
+
async function initCSSCompiler(input) {
|
|
8
|
+
initPromise ??= init(input).then(()=>{
|
|
9
|
+
setCSSTransform(transform);
|
|
10
|
+
});
|
|
11
|
+
await initPromise;
|
|
12
|
+
}
|
|
13
|
+
async function compileCSS(source, options = {}) {
|
|
14
|
+
await initCSSCompiler();
|
|
15
|
+
return compileCSS$1(source, options);
|
|
16
|
+
}
|
|
17
|
+
async function compileCSSManifest(source, options = {}) {
|
|
18
|
+
const result = await compileCSS(source, options);
|
|
19
|
+
if (result.references?.length) {
|
|
20
|
+
throw new Error('Browser compileCSSManifest cannot resolve @reference directives. Inline referenced CSS or compile the stylesheet in a Node environment.');
|
|
21
|
+
}
|
|
22
|
+
const { manifestInput: _manifestInput, ...directiveData } = result;
|
|
23
|
+
const lowerResult = lowerCSSDirectives(result, {
|
|
24
|
+
baseManifest: options.baseManifest,
|
|
25
|
+
onWarning: options.onWarning
|
|
26
|
+
});
|
|
27
|
+
const generatedCSS = lowerResult.generatedCSS || '';
|
|
28
|
+
const css = [
|
|
29
|
+
result.nativeCSS,
|
|
30
|
+
generatedCSS
|
|
31
|
+
].filter(Boolean).join('\n');
|
|
32
|
+
return {
|
|
33
|
+
...directiveData,
|
|
34
|
+
dependencies: [],
|
|
35
|
+
manifest: lowerResult.manifest,
|
|
36
|
+
warnings: lowerResult.warnings,
|
|
37
|
+
generatedCSS,
|
|
38
|
+
css,
|
|
39
|
+
directives: result
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async function parseDirectives(source, options = {}) {
|
|
43
|
+
await initCSSCompiler();
|
|
44
|
+
return parseDirectives$1(source, options);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { compileCSS, compileCSSManifest, initCSSCompiler, parseDirectives };
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type CSSDirectiveManifestInput, type CSSDirectiveReference, type CSSDirectiveResult, type CSSDirectiveStyleDefinition } from '@master/css-schema/css-directives';
|
|
2
|
+
import { setCSSTransform, type CSSTransform } from './css-transform';
|
|
3
|
+
import { createSourceLocationResolver, type CSSDirectiveRuleRange } from '@master/css-lexer';
|
|
4
|
+
import { collectStandaloneCSSDirectiveExtractionPolicy, createCSSDirectiveExtractionPolicy, findStandaloneCSSDirectiveStatements, findStandaloneMasterDirectiveStatements, mergeCSSDirectiveExtractionPolicy, removeStandaloneCSSDirectives, removeStandaloneMasterDirectives, type StandaloneCSSDirectiveStatement, type StandaloneMasterDirectiveStatement } from './lexer/standalone-master';
|
|
5
|
+
export { collectStandaloneCSSDirectiveExtractionPolicy, createCSSDirectiveExtractionPolicy, findStandaloneCSSDirectiveStatements, findStandaloneMasterDirectiveStatements, mergeCSSDirectiveExtractionPolicy, removeStandaloneCSSDirectives, removeStandaloneMasterDirectives, setCSSTransform };
|
|
6
|
+
export type { CSSTransform, StandaloneCSSDirectiveStatement, StandaloneMasterDirectiveStatement };
|
|
7
|
+
export interface CompileCSSOptions {
|
|
8
|
+
classes?: string[];
|
|
9
|
+
from?: string;
|
|
10
|
+
preserveNativeCSS?: boolean;
|
|
11
|
+
onWarning?: (warning: string) => void;
|
|
12
|
+
}
|
|
13
|
+
export interface CompileCSSFileOptions extends CompileCSSOptions {
|
|
14
|
+
root?: string;
|
|
15
|
+
}
|
|
16
|
+
export type CompileCSSResult = CSSDirectiveResult;
|
|
17
|
+
export interface ResolvedCSSImportGraph {
|
|
18
|
+
source: string;
|
|
19
|
+
dependencies: string[];
|
|
20
|
+
references?: CSSDirectiveReference[];
|
|
21
|
+
}
|
|
22
|
+
type ParsedStyleDefinition = CSSDirectiveStyleDefinition;
|
|
23
|
+
export interface ParsedDirectives extends Pick<CompileCSSResult, 'manifestInput' | 'extractionPolicy' | 'classNames' | 'nativeClassNames' | 'warnings'> {
|
|
24
|
+
styleDefinitions?: ParsedStyleDefinition[];
|
|
25
|
+
styleOrder?: number;
|
|
26
|
+
source?: string;
|
|
27
|
+
filename?: string;
|
|
28
|
+
composeRanges?: CSSDirectiveRuleRange[];
|
|
29
|
+
composeRangeIndex?: number;
|
|
30
|
+
sourceLocationResolver?: ReturnType<typeof createSourceLocationResolver>;
|
|
31
|
+
}
|
|
32
|
+
export interface CSSReferenceStatement extends CSSDirectiveReference {
|
|
33
|
+
start: number;
|
|
34
|
+
end: number;
|
|
35
|
+
statement: string;
|
|
36
|
+
}
|
|
37
|
+
export declare function findCSSReferenceStatements(source: string, filename?: string): CSSReferenceStatement[];
|
|
38
|
+
export declare function removeCSSReferenceStatements(source: string, filename?: string): string;
|
|
39
|
+
export declare function maskManagedPatternEntryNames(source: string): string;
|
|
40
|
+
export declare function compileCSS(source: string, options?: CompileCSSOptions): CompileCSSResult;
|
|
41
|
+
export declare function parseDirectives(source: string, options?: CompileCSSOptions): {
|
|
42
|
+
styleDefinitions?: CSSDirectiveStyleDefinition[] | undefined;
|
|
43
|
+
manifestInput: CSSDirectiveManifestInput;
|
|
44
|
+
extractionPolicy: import("@master/css-schema/css-directives").CSSDirectiveExtractionPolicy;
|
|
45
|
+
classNames: string[];
|
|
46
|
+
nativeClassNames: string[];
|
|
47
|
+
warnings: string[];
|
|
48
|
+
};
|