@menapo/vicss 0.0.0-stage → 1.0.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/vite.d.ts ADDED
@@ -0,0 +1,245 @@
1
+ import { Plugin } from "vite";
2
+ //#region src/core/types.d.ts
3
+ /** Token scales a property can draw its values from. */
4
+ type ScaleName = "colors" | "spacing" | "sizes" | "radii" | "fonts" | "fontSizes" | "fontWeights" | "lineHeights" | "letterSpacings" | "shadows" | "textShadows" | "durations" | "easings" | "zIndices" | "opacities" | "blurs" | "aspectRatios" | "breakpoints" | "containers";
5
+ /** A style object as authors write it. Values are checked by `normalizeStyle`. */
6
+ interface StyleObject {
7
+ [key: string]: StyleValue | StyleObject | undefined;
8
+ }
9
+ type StyleValue = string | number | ConditionalValue | null | undefined;
10
+ /** `{ base: 4, _md: 6, _hover: { _md: 8 } }`: a value per condition. */
11
+ interface ConditionalValue {
12
+ [condition: string]: StyleValue;
13
+ }
14
+ /** A token tree node: a value, or a group of nodes. `DEFAULT` names the group itself. */
15
+ type TokenTree = {
16
+ [name: string]: string | number | TokenTree;
17
+ };
18
+ /** A semantic token: one value, or a value per mode (`{ base, _dark }`). */
19
+ type SemanticTokenValue = string | {
20
+ [modeOrBase: string]: string;
21
+ };
22
+ type SemanticTokenTree = {
23
+ [name: string]: SemanticTokenValue | SemanticTokenTree;
24
+ };
25
+ /** A utility turns one authored value into a style object (`size: 4` → width and height). */
26
+ interface UtilityDefinition {
27
+ /** Scale used to type and resolve the utility's value. */
28
+ readonly scale?: ScaleName;
29
+ /** `true`-only utilities (`truncate: true`) set this. */
30
+ readonly boolean?: boolean;
31
+ readonly transform: (value: string | number | boolean) => StyleObject;
32
+ }
33
+ interface VicssConfig {
34
+ presets?: VicssConfig[];
35
+ tokens?: { [scale in ScaleName]?: TokenTree; } & {
36
+ spacing?: TokenTree | {
37
+ step: string;
38
+ };
39
+ };
40
+ semanticTokens?: { [scale in ScaleName]?: SemanticTokenTree; };
41
+ textStyles?: Record<string, StyleObject>;
42
+ /** Extra named conditions: `"[data-brand=b] &"`, `"@media (…)"`, `"@container (…)"`, `"@supports (…)"`, `"&:is(…)"`. */
43
+ conditions?: Record<string, string | string[]>;
44
+ utilities?: Record<string, UtilityDefinition>;
45
+ /** Element styles by selector, printed in `@layer vicss.global` (PLAN §4.9). */
46
+ globalCss?: Record<string, StyleObject>;
47
+ /** `@keyframes` by name: frame selectors (`from`, `to`, `"50%"`) → style. */
48
+ keyframes?: Record<string, Record<string, StyleObject>>;
49
+ /** `@font-face` rules, descriptors in camelCase: `{ fontFamily: "Inter", src: "url(…)" }`. */
50
+ fontFaces?: Array<Record<string, string | number>>;
51
+ /** How `_dark` and semantic-token dark values are selected (PLAN D12). */
52
+ darkMode?: "attribute-or-media" | "attribute" | "media" | {
53
+ selector: string;
54
+ };
55
+ /**
56
+ * What a value outside a property's scale may be (PLAN D8): one level for
57
+ * every scale, or levels by scale, property or utility name, with
58
+ * `default` for the rest (`{ default: "tokens", maxWidth: "css" }`).
59
+ */
60
+ strict?: Strictness | StrictnessMap;
61
+ reset?: boolean;
62
+ include?: string[];
63
+ exclude?: string[];
64
+ /** Modules that re-export the vicss runtime (a design system's `./ds`). */
65
+ importSources?: string[];
66
+ /** Prefix for token custom properties: `""` gives `--color-accent`. */
67
+ cssVarPrefix?: string;
68
+ /**
69
+ * Colour palettes (PLAN §4.8): styles write `palette.600`, and
70
+ * `colorPalette: "red"` points it at `colors.red.600` for an element and
71
+ * its subtree. Off without this key, which reserves the `colors.palette`
72
+ * group.
73
+ */
74
+ palettes?: PalettesConfig;
75
+ /**
76
+ * Which tokens app styles may name (PLAN §4.1, public and private
77
+ * tokens): a token pattern → `"private"` or `"public"`. `"colors"` is the
78
+ * scale's raw tokens (`tokens.colors`), `"colors.blue"` a token and every
79
+ * token under it, raw or semantic, and `*` one path segment
80
+ * (`"colors.*.950"`). The most specific pattern wins; presets mark their
81
+ * own tokens and the config changes any entry by its pattern.
82
+ */
83
+ tokenVisibility?: Record<string, TokenVisibility>;
84
+ /**
85
+ * Modules that belong to the design system and may name private tokens:
86
+ * globs relative to the root, like `include` (`"src/design-system/**"`),
87
+ * or an installed library's directory (`"node_modules/@acme/ui/**"`).
88
+ */
89
+ privateAccess?: string[];
90
+ /**
91
+ * The classes a build ships (PLAN §5.5, D31): `prefix` (default `"v"`)
92
+ * plus a hash of at least `minLength` characters (default 4, 6 in a
93
+ * library build), or the readable names dev serves (`md:p_6`) with
94
+ * `readable: true`. Dev serves readable names unless `readable` is false.
95
+ */
96
+ classNames?: {
97
+ prefix?: string;
98
+ minLength?: number;
99
+ readable?: boolean;
100
+ };
101
+ }
102
+ type TokenVisibility = "private" | "public";
103
+ interface PalettesConfig {
104
+ /** The palette of every element no `colorPalette` applies to: a colour group. */
105
+ default: string;
106
+ /**
107
+ * The colour groups `colorPalette` may name. Default: every top-level
108
+ * colour group, raw or semantic (`red` for `red.50` … `red.950`, `accent`
109
+ * for `accent` and `accent.hover`).
110
+ */
111
+ names?: string[];
112
+ }
113
+ /**
114
+ * PLAN D8. `"css"` (the default): a value outside the scale is written as
115
+ * it is when it is valid CSS for the property, and anything else (a typo of
116
+ * a token) fails the build. `"warn"`: the same, with a warning for each
117
+ * value outside the scale. `"tokens"`: only the scale's tokens, CSS-wide
118
+ * and the scale's keywords, percentages where the scale takes them, and
119
+ * zero. `"off"`: anything, unchecked.
120
+ */
121
+ type Strictness = "tokens" | "warn" | "css" | "off";
122
+ /** Levels by scale (`colors`), CSS property (`maxWidth`) or utility (`size`); `default` for the rest. */
123
+ type StrictnessMap = {
124
+ readonly default?: Strictness;
125
+ } & {
126
+ readonly [scaleOrProperty: string]: Strictness | undefined;
127
+ };
128
+ //#endregion
129
+ //#region src/core/compile.d.ts
130
+ type Framework = "react" | "preact" | "solid" | "vue" | "svelte" | "astro" | "vanilla";
131
+ //#endregion
132
+ //#region src/vite/critical.d.ts
133
+ /** What the plugin's `critical` option and `critical()` share. */
134
+ interface CriticalOptions {
135
+ /**
136
+ * Gzip bytes of a page's inline CSS above which the build warns. The page
137
+ * is still inlined. Default 14 000: what the first round trip of a new
138
+ * connection delivers (ten TCP segments), the HTML included.
139
+ */
140
+ budget?: number;
141
+ /**
142
+ * The JSON file listing each page's inline-style hashes for its
143
+ * Content-Security-Policy, relative to the output directory; `false`
144
+ * writes none. Default `vicss-critical.json`.
145
+ */
146
+ hashes?: string | false;
147
+ }
148
+ /** `critical()`'s options: the plugin's, and which pages to process. */
149
+ interface CriticalDirOptions extends CriticalOptions {
150
+ /** Pages to process, by path relative to the directory. Default: every `.html` file. */
151
+ filter?: (page: string) => boolean;
152
+ /** Report what would change and write nothing. */
153
+ dryRun?: boolean;
154
+ }
155
+ /** What each byte of a page's inline CSS is for, to say what to trim when it is over budget. */
156
+ type CriticalPart = "layers" | "tokens" | "global" | "atoms" | "fonts" | "keyframes" | "other";
157
+ interface CriticalPage {
158
+ /** Relative to the output directory, forward slashes: `index.html`, `blog/post/index.html`. */
159
+ readonly page: string;
160
+ /** The page's new HTML; absent when it was left as it was. */
161
+ readonly html?: string;
162
+ /** Why the page was left as it was. */
163
+ readonly skipped?: string;
164
+ /** Whether `skipped` is a warning: the page links vicss's CSS but could not take critical CSS. */
165
+ readonly warning?: boolean;
166
+ /** `sha256-…` of each inline `<style>`, in document order. */
167
+ readonly hashes: readonly string[];
168
+ /** The inline CSS, raw and gzipped, all styles together. */
169
+ readonly bytes: number;
170
+ readonly gzip: number;
171
+ /** Raw bytes of the inline CSS by what they are for. */
172
+ readonly parts: Readonly<Record<CriticalPart, number>>;
173
+ /** The stylesheets loaded from the end of `<body>` instead, as the output paths of their files. */
174
+ readonly deferred: readonly string[];
175
+ }
176
+ interface CriticalReport {
177
+ readonly pages: readonly CriticalPage[];
178
+ readonly budget: number;
179
+ /** The hashes file, relative to the output directory, when one was written. */
180
+ readonly hashesFile?: string;
181
+ /** One line for a log: how many pages, their sizes. */
182
+ readonly summary: string;
183
+ /** Pages over budget, and pages that link vicss's CSS but were left as they were. */
184
+ readonly warnings: readonly string[];
185
+ }
186
+ /**
187
+ * Inlines the critical CSS of every page under `dir`: the HTML a framework
188
+ * writes after `vite build` (Astro, SvelteKit, Vike, React Router
189
+ * prerendering), which no build hook sees. Pages are rewritten in place,
190
+ * a page processed before is left alone, and the hashes file is written.
191
+ */
192
+ export declare function critical(dir: string, options?: CriticalDirOptions): Promise<CriticalReport>;
193
+ //#endregion
194
+ //#region src/vite/plugin.d.ts
195
+ /** Delivery options (PLAN §5.10). Everything else lives in `vicss.config.ts`. */
196
+ interface VicssPluginOptions {
197
+ /**
198
+ * A path relative to the Vite root, or the config itself. Default: the
199
+ * first of `vicss.config.{ts,mts,js,mjs}` in the root, else an empty config.
200
+ */
201
+ config?: string | VicssConfig;
202
+ /** Outer cascade-layer order, e.g. `["reset", "vicss", "app"]`; must contain `"vicss"`. */
203
+ layers?: string[];
204
+ /**
205
+ * The SPA tokens file (PLAN D13), emitted when the client build has an
206
+ * HTML entry, which links it. `"auto"` (default) and `true` differ only in
207
+ * that `true` warns when there is no HTML entry; `false` keeps the tokens
208
+ * at the start of the sheet.
209
+ */
210
+ tokensFile?: "auto" | boolean;
211
+ /**
212
+ * The attributes `sx()` returns in plain `.js`/`.ts` modules (PLAN §5.12):
213
+ * `{ className, style }` for `"react"` and `"preact"`, `class` with a style
214
+ * object for `"vue"` and `"solid"`, `class` with a style string for the
215
+ * others. Default: the framework the root `package.json` depends on, else
216
+ * `"vanilla"`. Framework files and JSX modules go by their own framework.
217
+ * The generated `vicss.d.ts` registers it, which types `sx()`'s result.
218
+ */
219
+ framework?: Framework;
220
+ /**
221
+ * The generated `vicss.d.ts` (PLAN §5.11), written whenever the config
222
+ * loads, in dev and in builds, and only when its content changes, with
223
+ * the lint rules' `vicss.lint.json` next to it (`@menapo/vicss/lint`).
224
+ * Default: `src/vicss.d.ts` when the root has a `src` directory, else
225
+ * `app/vicss.d.ts` when it has an `app` one (Nuxt 4, React Router), else
226
+ * `vicss.d.ts`; `output` is relative to the root; `false` writes neither.
227
+ */
228
+ types?: false | {
229
+ output: string;
230
+ };
231
+ /**
232
+ * Critical CSS for prerendered pages (PLAN D16): in each HTML page the
233
+ * client build emits, every stylesheet holding vicss's CSS becomes an
234
+ * inline `<style>` with what the page's markup uses, and the stylesheet
235
+ * loads from the end of `<body>`, so it no longer blocks the first paint.
236
+ * The pages' CSP hashes go into `vicss-critical.json`. Pages a framework
237
+ * writes after the build take `vicss critical <outDir>`, or `critical()`
238
+ * from this entry. `"prerendered"` takes the defaults; `false`, like
239
+ * leaving it out, turns it off. Builds only.
240
+ */
241
+ critical?: false | "prerendered" | CriticalOptions;
242
+ }
243
+ export declare function vicss(options?: VicssPluginOptions): Plugin[];
244
+ //#endregion
245
+ export { type CriticalDirOptions, type CriticalOptions, type CriticalPage, type CriticalPart, type CriticalReport, type VicssPluginOptions, vicss as default };