@bamboocss/generator 1.12.2 → 1.13.1

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.
@@ -0,0 +1,122 @@
1
+ import { Context, StyleDecoder, Stylesheet } from "@bamboocss/core";
2
+ import { ArtifactId, CssArtifactType, LoadConfigResult, SpecFile, SpecType, SpecTypeMap } from "@bamboocss/types";
3
+
4
+ //#region src/generator.d.ts
5
+ interface SplitCssArtifact {
6
+ type: 'layer' | 'recipe' | 'theme';
7
+ name: string;
8
+ file: string;
9
+ code: string;
10
+ /** Directory relative to styles/ */
11
+ dir?: string;
12
+ }
13
+ interface SplitCssResult {
14
+ /** Layer CSS files (reset, global, tokens, utilities) */
15
+ layers: SplitCssArtifact[];
16
+ /** Recipe CSS files */
17
+ recipes: SplitCssArtifact[];
18
+ /** Theme CSS files (not auto-imported) */
19
+ themes: SplitCssArtifact[];
20
+ /** Content for recipes.css */
21
+ recipesIndex: string;
22
+ /** Content for main styles.css */
23
+ index: string;
24
+ }
25
+ declare class Generator extends Context {
26
+ constructor(conf: LoadConfigResult);
27
+ getArtifacts: (ids?: ArtifactId[] | undefined) => import("@bamboocss/types").Artifact[];
28
+ appendCssOfType: (type: CssArtifactType, sheet: Stylesheet) => void;
29
+ appendLayerParams: (sheet: Stylesheet) => void;
30
+ appendBaselineCss: (sheet: Stylesheet) => void;
31
+ appendParserCss: (sheet: Stylesheet) => void;
32
+ /**
33
+ * Drop token css variables nothing can reach. Call this only once the sheet holds the
34
+ * whole stylesheet — a baseline-only sheet has no utilities to reference anything, so
35
+ * every token would look unused.
36
+ *
37
+ * `keep` carries references this cannot see for itself; see `collectTokenReferences`.
38
+ */
39
+ pruneTokens: (sheet: Stylesheet, keep?: Set<string>) => {
40
+ removed: number;
41
+ kept: number;
42
+ } | undefined;
43
+ /**
44
+ * Drop `@keyframes` nothing can reach. Same completeness requirement as
45
+ * `pruneTokens`: the sheet has to hold the whole stylesheet, or every keyframe looks
46
+ * unused for want of a utility to reference it.
47
+ *
48
+ * `keep` carries names this cannot see for itself; see `collectKeyframeReferences`.
49
+ */
50
+ pruneKeyframes: (sheet: Stylesheet, keep?: Set<string>) => {
51
+ removed: number;
52
+ kept: number;
53
+ } | undefined;
54
+ /**
55
+ * Keyframes the themes name.
56
+ *
57
+ * A theme is emitted as its own artifact and injected at runtime, so its css is not in
58
+ * the sheet being pruned. A theme that points an animation token at a different
59
+ * keyframe than the base does — `--animations-enter: fade-in` in the base and
60
+ * `slide-up` under `dark` — would otherwise have that keyframe removed, because
61
+ * nothing in the pruned sheet ever names it.
62
+ */
63
+ private getThemeKeyframeNames;
64
+ /**
65
+ * Every custom property the token system declares. Used as the allow-list of what may
66
+ * be removed, so custom properties from `globalCss` are never touched.
67
+ */
68
+ private getTokenVarNames;
69
+ /**
70
+ * Everything the themes refer to.
71
+ *
72
+ * A theme is emitted as its own artifact and injected at runtime, so its css is not in
73
+ * the sheet being pruned and nothing there points at what it needs. A theme that maps a
74
+ * token onto a base colour would otherwise be left referring to a declaration that has
75
+ * been removed.
76
+ */
77
+ private getThemeTokenVars;
78
+ /**
79
+ * Tokens whose javascript value is a `var()` reference rather than a literal.
80
+ * `token('colors.text')` hands those to the caller as a reference, so the declaration
81
+ * has to survive whether or not the generated css mentions it. Ordinary tokens resolve
82
+ * to a literal in javascript and need no such exemption.
83
+ *
84
+ * The two cases mirror `generateTokenJs`, which is what decides the value javascript
85
+ * actually receives:
86
+ *
87
+ * - A virtual token, or one carrying a condition, is handed its own `varRef`.
88
+ * - A negative token is handed `calc(var(--x) * -1)`, so it is a reference too — but to
89
+ * the *positive* token's declaration. Its own var is never declared, so the name has
90
+ * to come out of the value.
91
+ */
92
+ private getAlwaysKeptTokenVars;
93
+ getParserCss: (decoder: StyleDecoder) => string;
94
+ getCss: (stylesheet?: Stylesheet) => string;
95
+ /**
96
+ * Get CSS for a specific layer from the stylesheet
97
+ */
98
+ getLayerCss: (sheet: Stylesheet, layer: "reset" | "base" | "tokens" | "recipes" | "utilities") => string;
99
+ /**
100
+ * Get CSS for a specific recipe
101
+ */
102
+ getRecipeCss: (recipeName: string) => string;
103
+ /**
104
+ * Get all recipe names from the decoder
105
+ */
106
+ getRecipeNames: () => string[];
107
+ /**
108
+ * Get all split CSS artifacts for the stylesheet
109
+ * Used when --splitting flag is enabled
110
+ */
111
+ getSplitCssArtifacts: (sheet: Stylesheet) => SplitCssResult;
112
+ getSpec: () => SpecFile[];
113
+ getSpecOfType: <T extends SpecType>(type: T) => T extends "color-palette" | "themes" ? SpecTypeMap[T] | undefined : SpecTypeMap[T];
114
+ }
115
+ //#endregion
116
+ //#region src/artifacts/js/themes.d.ts
117
+ /**
118
+ * Get CSS for a specific theme
119
+ */
120
+ declare function getThemeCss(ctx: Context, themeName: string): string;
121
+ //#endregion
122
+ export { Generator, SplitCssArtifact, SplitCssResult, getThemeCss };
@@ -0,0 +1,122 @@
1
+ import { Context, StyleDecoder, Stylesheet } from "@bamboocss/core";
2
+ import { ArtifactId, CssArtifactType, LoadConfigResult, SpecFile, SpecType, SpecTypeMap } from "@bamboocss/types";
3
+
4
+ //#region src/generator.d.ts
5
+ interface SplitCssArtifact {
6
+ type: 'layer' | 'recipe' | 'theme';
7
+ name: string;
8
+ file: string;
9
+ code: string;
10
+ /** Directory relative to styles/ */
11
+ dir?: string;
12
+ }
13
+ interface SplitCssResult {
14
+ /** Layer CSS files (reset, global, tokens, utilities) */
15
+ layers: SplitCssArtifact[];
16
+ /** Recipe CSS files */
17
+ recipes: SplitCssArtifact[];
18
+ /** Theme CSS files (not auto-imported) */
19
+ themes: SplitCssArtifact[];
20
+ /** Content for recipes.css */
21
+ recipesIndex: string;
22
+ /** Content for main styles.css */
23
+ index: string;
24
+ }
25
+ declare class Generator extends Context {
26
+ constructor(conf: LoadConfigResult);
27
+ getArtifacts: (ids?: ArtifactId[] | undefined) => import("@bamboocss/types").Artifact[];
28
+ appendCssOfType: (type: CssArtifactType, sheet: Stylesheet) => void;
29
+ appendLayerParams: (sheet: Stylesheet) => void;
30
+ appendBaselineCss: (sheet: Stylesheet) => void;
31
+ appendParserCss: (sheet: Stylesheet) => void;
32
+ /**
33
+ * Drop token css variables nothing can reach. Call this only once the sheet holds the
34
+ * whole stylesheet — a baseline-only sheet has no utilities to reference anything, so
35
+ * every token would look unused.
36
+ *
37
+ * `keep` carries references this cannot see for itself; see `collectTokenReferences`.
38
+ */
39
+ pruneTokens: (sheet: Stylesheet, keep?: Set<string>) => {
40
+ removed: number;
41
+ kept: number;
42
+ } | undefined;
43
+ /**
44
+ * Drop `@keyframes` nothing can reach. Same completeness requirement as
45
+ * `pruneTokens`: the sheet has to hold the whole stylesheet, or every keyframe looks
46
+ * unused for want of a utility to reference it.
47
+ *
48
+ * `keep` carries names this cannot see for itself; see `collectKeyframeReferences`.
49
+ */
50
+ pruneKeyframes: (sheet: Stylesheet, keep?: Set<string>) => {
51
+ removed: number;
52
+ kept: number;
53
+ } | undefined;
54
+ /**
55
+ * Keyframes the themes name.
56
+ *
57
+ * A theme is emitted as its own artifact and injected at runtime, so its css is not in
58
+ * the sheet being pruned. A theme that points an animation token at a different
59
+ * keyframe than the base does — `--animations-enter: fade-in` in the base and
60
+ * `slide-up` under `dark` — would otherwise have that keyframe removed, because
61
+ * nothing in the pruned sheet ever names it.
62
+ */
63
+ private getThemeKeyframeNames;
64
+ /**
65
+ * Every custom property the token system declares. Used as the allow-list of what may
66
+ * be removed, so custom properties from `globalCss` are never touched.
67
+ */
68
+ private getTokenVarNames;
69
+ /**
70
+ * Everything the themes refer to.
71
+ *
72
+ * A theme is emitted as its own artifact and injected at runtime, so its css is not in
73
+ * the sheet being pruned and nothing there points at what it needs. A theme that maps a
74
+ * token onto a base colour would otherwise be left referring to a declaration that has
75
+ * been removed.
76
+ */
77
+ private getThemeTokenVars;
78
+ /**
79
+ * Tokens whose javascript value is a `var()` reference rather than a literal.
80
+ * `token('colors.text')` hands those to the caller as a reference, so the declaration
81
+ * has to survive whether or not the generated css mentions it. Ordinary tokens resolve
82
+ * to a literal in javascript and need no such exemption.
83
+ *
84
+ * The two cases mirror `generateTokenJs`, which is what decides the value javascript
85
+ * actually receives:
86
+ *
87
+ * - A virtual token, or one carrying a condition, is handed its own `varRef`.
88
+ * - A negative token is handed `calc(var(--x) * -1)`, so it is a reference too — but to
89
+ * the *positive* token's declaration. Its own var is never declared, so the name has
90
+ * to come out of the value.
91
+ */
92
+ private getAlwaysKeptTokenVars;
93
+ getParserCss: (decoder: StyleDecoder) => string;
94
+ getCss: (stylesheet?: Stylesheet) => string;
95
+ /**
96
+ * Get CSS for a specific layer from the stylesheet
97
+ */
98
+ getLayerCss: (sheet: Stylesheet, layer: "reset" | "base" | "tokens" | "recipes" | "utilities") => string;
99
+ /**
100
+ * Get CSS for a specific recipe
101
+ */
102
+ getRecipeCss: (recipeName: string) => string;
103
+ /**
104
+ * Get all recipe names from the decoder
105
+ */
106
+ getRecipeNames: () => string[];
107
+ /**
108
+ * Get all split CSS artifacts for the stylesheet
109
+ * Used when --splitting flag is enabled
110
+ */
111
+ getSplitCssArtifacts: (sheet: Stylesheet) => SplitCssResult;
112
+ getSpec: () => SpecFile[];
113
+ getSpecOfType: <T extends SpecType>(type: T) => T extends "color-palette" | "themes" ? SpecTypeMap[T] | undefined : SpecTypeMap[T];
114
+ }
115
+ //#endregion
116
+ //#region src/artifacts/js/themes.d.ts
117
+ /**
118
+ * Get CSS for a specific theme
119
+ */
120
+ declare function getThemeCss(ctx: Context, themeName: string): string;
121
+ //#endregion
122
+ export { Generator, SplitCssArtifact, SplitCssResult, getThemeCss };