@bamboocss/vite 1.13.0
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/index.cjs +1935 -0
- package/dist/index.d.cts +154 -0
- package/dist/index.d.mts +154 -0
- package/dist/index.mjs +1905 -0
- package/package.json +59 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { Context } from "@bamboocss/core";
|
|
2
|
+
import { Dict, ParserResultInterface } from "@bamboocss/types";
|
|
3
|
+
import MagicString from "magic-string";
|
|
4
|
+
import { Plugin } from "vite";
|
|
5
|
+
|
|
6
|
+
//#region src/runtime-css.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* The generated runtime's `css`, rebuilt in-process from a resolved context.
|
|
9
|
+
*
|
|
10
|
+
* A fold replaces a call with the string the runtime would have returned, so it has
|
|
11
|
+
* to compute that string the same way the runtime does — not the way the stylesheet
|
|
12
|
+
* does. The two differ in one respect that matters here: `StyleDecoder` escapes class
|
|
13
|
+
* names for use in a CSS selector (`.c_red\.300`), while the runtime emits the raw
|
|
14
|
+
* value that belongs in a `class` attribute (`c_red.300`). Folding the decoder's form
|
|
15
|
+
* would put a stray backslash in the DOM.
|
|
16
|
+
*
|
|
17
|
+
* Matching the runtime this way makes the substitution behaviour-preserving by
|
|
18
|
+
* construction. What still needs asserting — and is asserted in `__tests__` — is that
|
|
19
|
+
* these class names correspond to rules the build actually emits.
|
|
20
|
+
*
|
|
21
|
+
* Mirrors `generateCssFn` in `@bamboocss/generator`: `css = (...styles) =>
|
|
22
|
+
* cssFn(mergeCss(...styles))`.
|
|
23
|
+
*/
|
|
24
|
+
interface RuntimeCss {
|
|
25
|
+
(...styles: Dict[]): string;
|
|
26
|
+
}
|
|
27
|
+
declare const createRuntimeCss: (ctx: Context) => RuntimeCss;
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/fold.d.ts
|
|
30
|
+
/**
|
|
31
|
+
* Why a call site was left alone. Surfaced through `panda`-style diagnostics so a
|
|
32
|
+
* user can tell the difference between "this folded" and "this silently didn't".
|
|
33
|
+
*/
|
|
34
|
+
type SkipReason = 'dynamic' | 'raw-call' | 'not-foldable' | 'unsupported-kind' | 'not-imported' | 'no-call-expression' | 'overlapping' | 'empty';
|
|
35
|
+
interface FoldedCall {
|
|
36
|
+
name: string;
|
|
37
|
+
/** The class string resolved outright, empty when the whole call lowered to ternaries. */
|
|
38
|
+
className: string;
|
|
39
|
+
/**
|
|
40
|
+
* Every class literal the replacement emits, including both arms of each ternary — so a
|
|
41
|
+
* consumer checking that folded classes have CSS behind them sees the branches too,
|
|
42
|
+
* which `className` alone does not carry.
|
|
43
|
+
*/
|
|
44
|
+
classNames: string[];
|
|
45
|
+
start: number;
|
|
46
|
+
end: number;
|
|
47
|
+
}
|
|
48
|
+
interface SkippedCall {
|
|
49
|
+
name: string;
|
|
50
|
+
reason: SkipReason;
|
|
51
|
+
start: number;
|
|
52
|
+
end: number;
|
|
53
|
+
}
|
|
54
|
+
interface FoldResult {
|
|
55
|
+
code: string;
|
|
56
|
+
/** Null when nothing was folded, so callers can return the original module untouched. */
|
|
57
|
+
map: ReturnType<MagicString['generateMap']> | null;
|
|
58
|
+
folded: FoldedCall[];
|
|
59
|
+
skipped: SkippedCall[];
|
|
60
|
+
/**
|
|
61
|
+
* Other modules a folded value came from.
|
|
62
|
+
*
|
|
63
|
+
* The extractor resolves values across files, so `css(importedStyles, { … })` folds
|
|
64
|
+
* to a string that depends on a file this module only imports. Without registering
|
|
65
|
+
* that edge, editing the imported module leaves a stale literal behind in every
|
|
66
|
+
* consumer. Bundlers need these as watch files.
|
|
67
|
+
*/
|
|
68
|
+
dependencies: string[];
|
|
69
|
+
}
|
|
70
|
+
interface FoldOptions {
|
|
71
|
+
ctx: Context;
|
|
72
|
+
code: string;
|
|
73
|
+
parserResult: ParserResultInterface;
|
|
74
|
+
filePath: string;
|
|
75
|
+
/** Reuse one runtime `css` across files in a build. */
|
|
76
|
+
runtimeCss?: RuntimeCss;
|
|
77
|
+
/**
|
|
78
|
+
* Also collapse `styled.*` and pattern elements to the tag they render. On by default,
|
|
79
|
+
* since the JSX factory is where most style resolution happens at runtime.
|
|
80
|
+
*/
|
|
81
|
+
jsx?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Split a `css()` call or a `styled.*` element that is only partly static, keeping the
|
|
84
|
+
* dynamic half at runtime. On by default.
|
|
85
|
+
*/
|
|
86
|
+
partial?: boolean;
|
|
87
|
+
}
|
|
88
|
+
declare const foldSource: (options: FoldOptions) => FoldResult;
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/plugin.d.ts
|
|
91
|
+
interface BambooVitePluginOptions {
|
|
92
|
+
/**
|
|
93
|
+
* Rewrite statically-resolvable `css()` and pattern calls into literal class
|
|
94
|
+
* strings, so they cost nothing at runtime.
|
|
95
|
+
*
|
|
96
|
+
* Off by default, and build-only — see the "Source transformation" guide for why.
|
|
97
|
+
*
|
|
98
|
+
* @default false
|
|
99
|
+
*/
|
|
100
|
+
transform?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Also collapse `styled.*` and pattern elements to the tag they render, rather than
|
|
103
|
+
* folding call sites alone.
|
|
104
|
+
*
|
|
105
|
+
* On by default, and the larger of the two wins: the factory runs `splitProps`,
|
|
106
|
+
* `css()` and `cx` for every element on every render, inside a `forwardRef` component.
|
|
107
|
+
*
|
|
108
|
+
* @default true
|
|
109
|
+
*/
|
|
110
|
+
jsx?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Split a call or element that is only partly static, so the resolvable half becomes a
|
|
113
|
+
* literal and only the rest keeps its runtime call. On by default.
|
|
114
|
+
*
|
|
115
|
+
* Without it a single dynamic value declines the whole site.
|
|
116
|
+
*
|
|
117
|
+
* @default true
|
|
118
|
+
*/
|
|
119
|
+
partial?: boolean;
|
|
120
|
+
/** Path to `bamboo.config.ts`. Resolved the same way the CLI resolves it. */
|
|
121
|
+
configPath?: string;
|
|
122
|
+
cwd?: string;
|
|
123
|
+
/**
|
|
124
|
+
* Report every call site that did *not* fold, and why, per file. Useful when a call
|
|
125
|
+
* you expected to collapse still shows up in the bundle.
|
|
126
|
+
*
|
|
127
|
+
* @default false
|
|
128
|
+
*/
|
|
129
|
+
reportSkipped?: boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Print a coverage summary when the build finishes: how much folded, and what the
|
|
132
|
+
* remainder was declined for.
|
|
133
|
+
*
|
|
134
|
+
* On by default. Without it there is no signal that the transform did anything, and
|
|
135
|
+
* no way to tell a project where everything folds from one where nothing does.
|
|
136
|
+
*
|
|
137
|
+
* @default true
|
|
138
|
+
*/
|
|
139
|
+
reportSummary?: boolean;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Vite integration for Bamboo CSS.
|
|
143
|
+
*
|
|
144
|
+
* This plugin does not emit CSS — keep your existing PostCSS setup for that. Its only
|
|
145
|
+
* job is the optional build-time fold.
|
|
146
|
+
*
|
|
147
|
+
* It runs with `enforce: 'pre'` so it sees module source as close as possible to what
|
|
148
|
+
* the CSS extractor reads off disk. A plugin that rewrites style calls before bamboo
|
|
149
|
+
* sees them would otherwise make the two disagree, and a folded class could end up
|
|
150
|
+
* with no matching rule.
|
|
151
|
+
*/
|
|
152
|
+
declare const bamboocss: (options?: BambooVitePluginOptions) => Plugin;
|
|
153
|
+
//#endregion
|
|
154
|
+
export { type BambooVitePluginOptions, type FoldOptions, type FoldResult, type FoldedCall, type RuntimeCss, type SkipReason, type SkippedCall, bamboocss, bamboocss as default, createRuntimeCss, foldSource };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import MagicString from "magic-string";
|
|
2
|
+
import { Context } from "@bamboocss/core";
|
|
3
|
+
import { Dict, ParserResultInterface } from "@bamboocss/types";
|
|
4
|
+
import { Plugin } from "vite";
|
|
5
|
+
|
|
6
|
+
//#region src/runtime-css.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* The generated runtime's `css`, rebuilt in-process from a resolved context.
|
|
9
|
+
*
|
|
10
|
+
* A fold replaces a call with the string the runtime would have returned, so it has
|
|
11
|
+
* to compute that string the same way the runtime does — not the way the stylesheet
|
|
12
|
+
* does. The two differ in one respect that matters here: `StyleDecoder` escapes class
|
|
13
|
+
* names for use in a CSS selector (`.c_red\.300`), while the runtime emits the raw
|
|
14
|
+
* value that belongs in a `class` attribute (`c_red.300`). Folding the decoder's form
|
|
15
|
+
* would put a stray backslash in the DOM.
|
|
16
|
+
*
|
|
17
|
+
* Matching the runtime this way makes the substitution behaviour-preserving by
|
|
18
|
+
* construction. What still needs asserting — and is asserted in `__tests__` — is that
|
|
19
|
+
* these class names correspond to rules the build actually emits.
|
|
20
|
+
*
|
|
21
|
+
* Mirrors `generateCssFn` in `@bamboocss/generator`: `css = (...styles) =>
|
|
22
|
+
* cssFn(mergeCss(...styles))`.
|
|
23
|
+
*/
|
|
24
|
+
interface RuntimeCss {
|
|
25
|
+
(...styles: Dict[]): string;
|
|
26
|
+
}
|
|
27
|
+
declare const createRuntimeCss: (ctx: Context) => RuntimeCss;
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/fold.d.ts
|
|
30
|
+
/**
|
|
31
|
+
* Why a call site was left alone. Surfaced through `panda`-style diagnostics so a
|
|
32
|
+
* user can tell the difference between "this folded" and "this silently didn't".
|
|
33
|
+
*/
|
|
34
|
+
type SkipReason = 'dynamic' | 'raw-call' | 'not-foldable' | 'unsupported-kind' | 'not-imported' | 'no-call-expression' | 'overlapping' | 'empty';
|
|
35
|
+
interface FoldedCall {
|
|
36
|
+
name: string;
|
|
37
|
+
/** The class string resolved outright, empty when the whole call lowered to ternaries. */
|
|
38
|
+
className: string;
|
|
39
|
+
/**
|
|
40
|
+
* Every class literal the replacement emits, including both arms of each ternary — so a
|
|
41
|
+
* consumer checking that folded classes have CSS behind them sees the branches too,
|
|
42
|
+
* which `className` alone does not carry.
|
|
43
|
+
*/
|
|
44
|
+
classNames: string[];
|
|
45
|
+
start: number;
|
|
46
|
+
end: number;
|
|
47
|
+
}
|
|
48
|
+
interface SkippedCall {
|
|
49
|
+
name: string;
|
|
50
|
+
reason: SkipReason;
|
|
51
|
+
start: number;
|
|
52
|
+
end: number;
|
|
53
|
+
}
|
|
54
|
+
interface FoldResult {
|
|
55
|
+
code: string;
|
|
56
|
+
/** Null when nothing was folded, so callers can return the original module untouched. */
|
|
57
|
+
map: ReturnType<MagicString['generateMap']> | null;
|
|
58
|
+
folded: FoldedCall[];
|
|
59
|
+
skipped: SkippedCall[];
|
|
60
|
+
/**
|
|
61
|
+
* Other modules a folded value came from.
|
|
62
|
+
*
|
|
63
|
+
* The extractor resolves values across files, so `css(importedStyles, { … })` folds
|
|
64
|
+
* to a string that depends on a file this module only imports. Without registering
|
|
65
|
+
* that edge, editing the imported module leaves a stale literal behind in every
|
|
66
|
+
* consumer. Bundlers need these as watch files.
|
|
67
|
+
*/
|
|
68
|
+
dependencies: string[];
|
|
69
|
+
}
|
|
70
|
+
interface FoldOptions {
|
|
71
|
+
ctx: Context;
|
|
72
|
+
code: string;
|
|
73
|
+
parserResult: ParserResultInterface;
|
|
74
|
+
filePath: string;
|
|
75
|
+
/** Reuse one runtime `css` across files in a build. */
|
|
76
|
+
runtimeCss?: RuntimeCss;
|
|
77
|
+
/**
|
|
78
|
+
* Also collapse `styled.*` and pattern elements to the tag they render. On by default,
|
|
79
|
+
* since the JSX factory is where most style resolution happens at runtime.
|
|
80
|
+
*/
|
|
81
|
+
jsx?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Split a `css()` call or a `styled.*` element that is only partly static, keeping the
|
|
84
|
+
* dynamic half at runtime. On by default.
|
|
85
|
+
*/
|
|
86
|
+
partial?: boolean;
|
|
87
|
+
}
|
|
88
|
+
declare const foldSource: (options: FoldOptions) => FoldResult;
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/plugin.d.ts
|
|
91
|
+
interface BambooVitePluginOptions {
|
|
92
|
+
/**
|
|
93
|
+
* Rewrite statically-resolvable `css()` and pattern calls into literal class
|
|
94
|
+
* strings, so they cost nothing at runtime.
|
|
95
|
+
*
|
|
96
|
+
* Off by default, and build-only — see the "Source transformation" guide for why.
|
|
97
|
+
*
|
|
98
|
+
* @default false
|
|
99
|
+
*/
|
|
100
|
+
transform?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Also collapse `styled.*` and pattern elements to the tag they render, rather than
|
|
103
|
+
* folding call sites alone.
|
|
104
|
+
*
|
|
105
|
+
* On by default, and the larger of the two wins: the factory runs `splitProps`,
|
|
106
|
+
* `css()` and `cx` for every element on every render, inside a `forwardRef` component.
|
|
107
|
+
*
|
|
108
|
+
* @default true
|
|
109
|
+
*/
|
|
110
|
+
jsx?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Split a call or element that is only partly static, so the resolvable half becomes a
|
|
113
|
+
* literal and only the rest keeps its runtime call. On by default.
|
|
114
|
+
*
|
|
115
|
+
* Without it a single dynamic value declines the whole site.
|
|
116
|
+
*
|
|
117
|
+
* @default true
|
|
118
|
+
*/
|
|
119
|
+
partial?: boolean;
|
|
120
|
+
/** Path to `bamboo.config.ts`. Resolved the same way the CLI resolves it. */
|
|
121
|
+
configPath?: string;
|
|
122
|
+
cwd?: string;
|
|
123
|
+
/**
|
|
124
|
+
* Report every call site that did *not* fold, and why, per file. Useful when a call
|
|
125
|
+
* you expected to collapse still shows up in the bundle.
|
|
126
|
+
*
|
|
127
|
+
* @default false
|
|
128
|
+
*/
|
|
129
|
+
reportSkipped?: boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Print a coverage summary when the build finishes: how much folded, and what the
|
|
132
|
+
* remainder was declined for.
|
|
133
|
+
*
|
|
134
|
+
* On by default. Without it there is no signal that the transform did anything, and
|
|
135
|
+
* no way to tell a project where everything folds from one where nothing does.
|
|
136
|
+
*
|
|
137
|
+
* @default true
|
|
138
|
+
*/
|
|
139
|
+
reportSummary?: boolean;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Vite integration for Bamboo CSS.
|
|
143
|
+
*
|
|
144
|
+
* This plugin does not emit CSS — keep your existing PostCSS setup for that. Its only
|
|
145
|
+
* job is the optional build-time fold.
|
|
146
|
+
*
|
|
147
|
+
* It runs with `enforce: 'pre'` so it sees module source as close as possible to what
|
|
148
|
+
* the CSS extractor reads off disk. A plugin that rewrites style calls before bamboo
|
|
149
|
+
* sees them would otherwise make the two disagree, and a folded class could end up
|
|
150
|
+
* with no matching rule.
|
|
151
|
+
*/
|
|
152
|
+
declare const bamboocss: (options?: BambooVitePluginOptions) => Plugin;
|
|
153
|
+
//#endregion
|
|
154
|
+
export { type BambooVitePluginOptions, type FoldOptions, type FoldResult, type FoldedCall, type RuntimeCss, type SkipReason, type SkippedCall, bamboocss, bamboocss as default, createRuntimeCss, foldSource };
|