@vertz/ui-compiler 0.2.3
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 +19 -0
- package/dist/index.d.ts +564 -0
- package/dist/index.js +3139 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @vertz/ui-compiler
|
|
2
|
+
|
|
3
|
+
> **Internal package** — You don't use this directly. It powers the reactive compiler behind `@vertz/ui`.
|
|
4
|
+
|
|
5
|
+
The UI compiler transforms `@vertz/ui` components at build time — converting `let` declarations into signals, wrapping derived `const` values in `computed()`, inserting `.value` accessors, and generating getter-based props for cross-component reactivity.
|
|
6
|
+
|
|
7
|
+
## Who uses this
|
|
8
|
+
|
|
9
|
+
- **`@vertz/ui-server`** — The Bun plugin loads this compiler to transform `.tsx` files during development and SSR.
|
|
10
|
+
- **Framework contributors** — If you're working on the compiler itself, see the source in `src/` for architecture details.
|
|
11
|
+
|
|
12
|
+
## Related Packages
|
|
13
|
+
|
|
14
|
+
- [`@vertz/ui`](../ui) — The UI framework this compiler targets
|
|
15
|
+
- [`@vertz/ui-server`](../ui-server) — Dev server and SSR runtime that invokes the compiler
|
|
16
|
+
|
|
17
|
+
## License
|
|
18
|
+
|
|
19
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,564 @@
|
|
|
1
|
+
import { SourceFile } from "ts-morph";
|
|
2
|
+
/** Options for the compile() function. */
|
|
3
|
+
interface CompileOptions {
|
|
4
|
+
/** Filename for source map generation. Defaults to 'input.tsx'. */
|
|
5
|
+
filename?: string;
|
|
6
|
+
/** Compilation target. 'dom' uses @vertz/ui/internals, 'tui' uses @vertz/tui/internals. */
|
|
7
|
+
target?: "dom" | "tui";
|
|
8
|
+
}
|
|
9
|
+
/** Severity of a compiler diagnostic. */
|
|
10
|
+
type DiagnosticSeverity = "error" | "warning" | "info";
|
|
11
|
+
/** A diagnostic message emitted during compilation. */
|
|
12
|
+
interface CompilerDiagnostic {
|
|
13
|
+
/** Unique code identifying this diagnostic kind. */
|
|
14
|
+
code: string;
|
|
15
|
+
/** Human-readable message. */
|
|
16
|
+
message: string;
|
|
17
|
+
/** Severity level. */
|
|
18
|
+
severity: DiagnosticSeverity;
|
|
19
|
+
/** 1-based line number in source. */
|
|
20
|
+
line: number;
|
|
21
|
+
/** 0-based column offset. */
|
|
22
|
+
column: number;
|
|
23
|
+
/** Optional fix suggestion. */
|
|
24
|
+
fix?: string;
|
|
25
|
+
}
|
|
26
|
+
/** Result of a compile() call. */
|
|
27
|
+
interface CompileOutput {
|
|
28
|
+
/** Transformed source code. */
|
|
29
|
+
code: string;
|
|
30
|
+
/** Source map (v3 JSON). */
|
|
31
|
+
map: {
|
|
32
|
+
version: number;
|
|
33
|
+
sources: string[];
|
|
34
|
+
sourcesContent?: string[];
|
|
35
|
+
mappings: string;
|
|
36
|
+
names: string[];
|
|
37
|
+
};
|
|
38
|
+
/** Diagnostics produced during compilation. */
|
|
39
|
+
diagnostics: CompilerDiagnostic[];
|
|
40
|
+
}
|
|
41
|
+
/** Classification of a variable's reactivity. */
|
|
42
|
+
type ReactivityKind = "signal" | "computed" | "static";
|
|
43
|
+
/** Information about a variable inside a component. */
|
|
44
|
+
interface VariableInfo {
|
|
45
|
+
/** Variable name. */
|
|
46
|
+
name: string;
|
|
47
|
+
/** Reactivity classification. */
|
|
48
|
+
kind: ReactivityKind;
|
|
49
|
+
/** 0-based start position of the declaration in source. */
|
|
50
|
+
start: number;
|
|
51
|
+
/** 0-based end position of the declaration in source. */
|
|
52
|
+
end: number;
|
|
53
|
+
/**
|
|
54
|
+
* Signal properties on this variable (for signal-returning APIs like query()).
|
|
55
|
+
*
|
|
56
|
+
* @remarks
|
|
57
|
+
* Uses `Set<string>` for O(1) lookup performance during transformation.
|
|
58
|
+
* **Not JSON-serializable** — if this type is serialized (e.g., for caching or IPC),
|
|
59
|
+
* convert to `Array.from(signalProperties)` before serialization and reconstruct
|
|
60
|
+
* the Set on deserialization.
|
|
61
|
+
*/
|
|
62
|
+
signalProperties?: Set<string>;
|
|
63
|
+
/** Plain (non-signal) properties on this variable. */
|
|
64
|
+
plainProperties?: Set<string>;
|
|
65
|
+
/** Per-field signal properties (e.g., form().title.error). */
|
|
66
|
+
fieldSignalProperties?: Set<string>;
|
|
67
|
+
/** Synthetic variable name this binding was destructured from (e.g., `__query_0`). */
|
|
68
|
+
destructuredFrom?: string;
|
|
69
|
+
/** Whether this variable is a reactive source (e.g., useContext result). */
|
|
70
|
+
isReactiveSource?: boolean;
|
|
71
|
+
}
|
|
72
|
+
/** Information about a detected component function. */
|
|
73
|
+
interface ComponentInfo {
|
|
74
|
+
/** Component function name. */
|
|
75
|
+
name: string;
|
|
76
|
+
/** Name of the props parameter (e.g. "props"), or null if none. */
|
|
77
|
+
propsParam: string | null;
|
|
78
|
+
/** Whether the props parameter uses destructuring. */
|
|
79
|
+
hasDestructuredProps: boolean;
|
|
80
|
+
/** 0-based start position of the function body. */
|
|
81
|
+
bodyStart: number;
|
|
82
|
+
/** 0-based end position of the function body. */
|
|
83
|
+
bodyEnd: number;
|
|
84
|
+
}
|
|
85
|
+
/** Classification of a JSX expression's reactivity. */
|
|
86
|
+
interface JsxExpressionInfo {
|
|
87
|
+
/** 0-based start of the expression in source. */
|
|
88
|
+
start: number;
|
|
89
|
+
/** 0-based end of the expression in source. */
|
|
90
|
+
end: number;
|
|
91
|
+
/** Whether this expression depends on reactive variables. */
|
|
92
|
+
reactive: boolean;
|
|
93
|
+
/** Names of reactive variables referenced. */
|
|
94
|
+
deps: string[];
|
|
95
|
+
}
|
|
96
|
+
/** Kinds of in-place mutations on signal variables. */
|
|
97
|
+
type MutationKind = "method-call" | "property-assignment" | "index-assignment" | "delete" | "object-assign";
|
|
98
|
+
/** A detected in-place mutation on a signal variable. */
|
|
99
|
+
interface MutationInfo {
|
|
100
|
+
/** The signal variable name being mutated. */
|
|
101
|
+
variableName: string;
|
|
102
|
+
/** Kind of mutation. */
|
|
103
|
+
kind: MutationKind;
|
|
104
|
+
/** 0-based start of the mutation expression. */
|
|
105
|
+
start: number;
|
|
106
|
+
/** 0-based end of the mutation expression. */
|
|
107
|
+
end: number;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Detect functions that return JSX — the component boundaries
|
|
111
|
+
* the compiler operates within.
|
|
112
|
+
*/
|
|
113
|
+
declare class ComponentAnalyzer {
|
|
114
|
+
analyze(sourceFile: SourceFile): ComponentInfo[];
|
|
115
|
+
/**
|
|
116
|
+
* Check whether a function contains JSX — either in a return statement
|
|
117
|
+
* or anywhere in the function body (e.g., variable assignments, loops,
|
|
118
|
+
* function call arguments).
|
|
119
|
+
*/
|
|
120
|
+
private _returnsJsx;
|
|
121
|
+
private _containsJsx;
|
|
122
|
+
private _fromFunctionDeclaration;
|
|
123
|
+
private _fromVariableDeclaration;
|
|
124
|
+
}
|
|
125
|
+
import { SourceFile as SourceFile2 } from "ts-morph";
|
|
126
|
+
/** Classification of a css() call. */
|
|
127
|
+
type CSSCallKind = "static" | "reactive";
|
|
128
|
+
/** Information about a detected css() call. */
|
|
129
|
+
interface CSSCallInfo {
|
|
130
|
+
/** Whether the call can be fully resolved at compile time. */
|
|
131
|
+
kind: CSSCallKind;
|
|
132
|
+
/** 0-based start position of the entire css() call expression. */
|
|
133
|
+
start: number;
|
|
134
|
+
/** 0-based end position of the entire css() call expression. */
|
|
135
|
+
end: number;
|
|
136
|
+
/** 1-based line number. */
|
|
137
|
+
line: number;
|
|
138
|
+
/** 0-based column. */
|
|
139
|
+
column: number;
|
|
140
|
+
/** The raw source text of the css() call. */
|
|
141
|
+
text: string;
|
|
142
|
+
/** For static calls: the parsed block names. */
|
|
143
|
+
blockNames: string[];
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Analyze a source file for css() calls.
|
|
147
|
+
*/
|
|
148
|
+
declare class CSSAnalyzer {
|
|
149
|
+
analyze(sourceFile: SourceFile2): CSSCallInfo[];
|
|
150
|
+
/** Classify whether a css() argument is fully static. */
|
|
151
|
+
private classifyArgument;
|
|
152
|
+
/** Check if a nested object (for complex selectors) is fully static. */
|
|
153
|
+
private isStaticNestedObject;
|
|
154
|
+
/** Check if a node is a static raw declaration: { property: '...', value: '...' } */
|
|
155
|
+
private isStaticRawDeclaration;
|
|
156
|
+
/** Extract block names from a static css() argument. */
|
|
157
|
+
private extractBlockNames;
|
|
158
|
+
}
|
|
159
|
+
import { SourceFile as SourceFile3 } from "ts-morph";
|
|
160
|
+
/**
|
|
161
|
+
* Map each JSX expression/attribute to its dependencies.
|
|
162
|
+
* Classify as reactive or static based on whether any dependency is a signal,
|
|
163
|
+
* computed, or a signal API property access (e.g., query().data, form().submitting).
|
|
164
|
+
*/
|
|
165
|
+
declare class JsxAnalyzer {
|
|
166
|
+
analyze(sourceFile: SourceFile3, component: ComponentInfo, variables: VariableInfo[]): JsxExpressionInfo[];
|
|
167
|
+
}
|
|
168
|
+
import { SourceFile as SourceFile4 } from "ts-morph";
|
|
169
|
+
/**
|
|
170
|
+
* Detect in-place mutations on signal variables.
|
|
171
|
+
* These need special treatment: peek() + notify() pattern.
|
|
172
|
+
*/
|
|
173
|
+
declare class MutationAnalyzer {
|
|
174
|
+
analyze(sourceFile: SourceFile4, component: ComponentInfo, variables: VariableInfo[]): MutationInfo[];
|
|
175
|
+
}
|
|
176
|
+
import { SourceFile as SourceFile5 } from "ts-morph";
|
|
177
|
+
/**
|
|
178
|
+
* Two-pass taint analysis classifying variables as signal, computed, or static.
|
|
179
|
+
*
|
|
180
|
+
* Pass 1: Collect all `let` and `const` declarations in the component body,
|
|
181
|
+
* along with their dependency references.
|
|
182
|
+
* Pass 2: Starting from JSX-referenced identifiers, trace backwards through
|
|
183
|
+
* const dependency chains to find which `let` vars are "needed" by JSX.
|
|
184
|
+
* Those `let` vars become signals, and the intermediate consts become computeds.
|
|
185
|
+
*/
|
|
186
|
+
declare class ReactivityAnalyzer {
|
|
187
|
+
analyze(sourceFile: SourceFile5, component: ComponentInfo): VariableInfo[];
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Main compile pipeline.
|
|
191
|
+
*
|
|
192
|
+
* 1. Parse → 2. Component analysis → 3. Reactivity analysis →
|
|
193
|
+
* 4. Mutation analysis + transform → 5. Signal transform →
|
|
194
|
+
* 6. Computed transform → 7. JSX analysis →
|
|
195
|
+
* 8. JSX transform (includes prop transform) →
|
|
196
|
+
* 9. Diagnostics → 10. Add imports → 11. Return { code, map, diagnostics }
|
|
197
|
+
*/
|
|
198
|
+
declare function compile(source: string, optionsOrFilename?: CompileOptions | string): CompileOutput;
|
|
199
|
+
/** Result of extracting CSS from a source file. */
|
|
200
|
+
interface CSSExtractionResult {
|
|
201
|
+
/** The extracted CSS rules as a string. */
|
|
202
|
+
css: string;
|
|
203
|
+
/** The block names found in static css() calls. */
|
|
204
|
+
blockNames: string[];
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Extracts CSS from css() calls in source code.
|
|
208
|
+
* Produces a CSS string and list of block names for each file.
|
|
209
|
+
*/
|
|
210
|
+
declare class CSSExtractor {
|
|
211
|
+
/**
|
|
212
|
+
* Extract CSS from all static css() calls in the given source.
|
|
213
|
+
* @param source - The source code to analyze.
|
|
214
|
+
* @param filePath - The file path (used for deterministic class name generation).
|
|
215
|
+
* @returns The extracted CSS and block names.
|
|
216
|
+
*/
|
|
217
|
+
extract(source: string, filePath: string): CSSExtractionResult;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Splits extracted CSS into per-route chunks with a shared common chunk.
|
|
221
|
+
*/
|
|
222
|
+
declare class CSSCodeSplitter {
|
|
223
|
+
/**
|
|
224
|
+
* Split CSS by route, extracting shared CSS into a common chunk.
|
|
225
|
+
*
|
|
226
|
+
* @param manifest - Map of route path to list of CSS-contributing file paths.
|
|
227
|
+
* @param fileExtractions - Map of file path to CSS extraction result.
|
|
228
|
+
* @returns Record of route path (or `__common`) to CSS string.
|
|
229
|
+
*/
|
|
230
|
+
split(manifest: Map<string, string[]>, fileExtractions: Map<string, CSSExtractionResult>): Record<string, string>;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Eliminates CSS from modules that are not in the used set.
|
|
234
|
+
*/
|
|
235
|
+
declare class DeadCSSEliminator {
|
|
236
|
+
/**
|
|
237
|
+
* Filter extracted CSS to only include styles from used modules.
|
|
238
|
+
*
|
|
239
|
+
* @param extractions - Map of file path to extraction result.
|
|
240
|
+
* @param usedFiles - Set of file paths that are reachable in the module graph.
|
|
241
|
+
* @returns Combined CSS from only the used modules.
|
|
242
|
+
*/
|
|
243
|
+
eliminate(extractions: Map<string, CSSExtractionResult>, usedFiles: Set<string>): string;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* CSS HMR Integration for Vite Dev Mode.
|
|
247
|
+
*
|
|
248
|
+
* When a css() call changes, only the affected CSS is hot-replaced.
|
|
249
|
+
* No full page reload needed for style changes. This module provides
|
|
250
|
+
* the invalidation logic that a Vite plugin would call — it does not
|
|
251
|
+
* need to BE a Vite plugin itself.
|
|
252
|
+
*
|
|
253
|
+
* Usage from a Vite plugin:
|
|
254
|
+
* 1. On file load: handler.register(filePath, extractedCSS)
|
|
255
|
+
* 2. On file change: handler.update(filePath, newCSS) -> { hasChanged, css, affectedFiles }
|
|
256
|
+
* 3. If hasChanged: inject the new CSS via Vite's HMR API
|
|
257
|
+
*/
|
|
258
|
+
/** Result of a CSS HMR update check. */
|
|
259
|
+
interface CSSHMRUpdateResult {
|
|
260
|
+
/** Whether the CSS actually changed. */
|
|
261
|
+
hasChanged: boolean;
|
|
262
|
+
/** The new CSS content (only meaningful if hasChanged is true). */
|
|
263
|
+
css: string;
|
|
264
|
+
/** List of file paths whose CSS was affected. */
|
|
265
|
+
affectedFiles: string[];
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Tracks CSS state per file and provides change detection for HMR.
|
|
269
|
+
*/
|
|
270
|
+
declare class CSSHMRHandler {
|
|
271
|
+
/** Map of file path to its last known CSS content. */
|
|
272
|
+
private cssCache;
|
|
273
|
+
/**
|
|
274
|
+
* Register a file's extracted CSS. Called on initial load.
|
|
275
|
+
* @param filePath - The source file path.
|
|
276
|
+
* @param css - The extracted CSS content.
|
|
277
|
+
*/
|
|
278
|
+
register(filePath: string, css: string): void;
|
|
279
|
+
/**
|
|
280
|
+
* Check if a file's CSS has changed and update the cache.
|
|
281
|
+
* @param filePath - The source file path.
|
|
282
|
+
* @param newCSS - The newly extracted CSS content.
|
|
283
|
+
* @returns Update result with change status and affected files.
|
|
284
|
+
*/
|
|
285
|
+
update(filePath: string, newCSS: string): CSSHMRUpdateResult;
|
|
286
|
+
/**
|
|
287
|
+
* Remove a file from HMR tracking.
|
|
288
|
+
* @param filePath - The source file path to untrack.
|
|
289
|
+
*/
|
|
290
|
+
remove(filePath: string): void;
|
|
291
|
+
/**
|
|
292
|
+
* Get a full CSS snapshot of all tracked files.
|
|
293
|
+
* Useful for providing the complete CSS state to Vite's HMR API.
|
|
294
|
+
* @returns Combined CSS from all tracked files.
|
|
295
|
+
*/
|
|
296
|
+
getSnapshot(): string;
|
|
297
|
+
/**
|
|
298
|
+
* Get the number of tracked files.
|
|
299
|
+
*/
|
|
300
|
+
get size(): number;
|
|
301
|
+
/**
|
|
302
|
+
* Clear all tracked CSS state.
|
|
303
|
+
*/
|
|
304
|
+
clear(): void;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Builds a manifest mapping routes to their CSS file dependencies.
|
|
308
|
+
*/
|
|
309
|
+
declare class RouteCSSManifest {
|
|
310
|
+
/**
|
|
311
|
+
* Build a route-to-CSS manifest.
|
|
312
|
+
*
|
|
313
|
+
* @param routeToFiles - Map of route path to the component file paths used by that route.
|
|
314
|
+
* @param fileExtractions - Map of file path to CSS extraction result.
|
|
315
|
+
* @returns Map of route path to list of CSS-contributing file paths.
|
|
316
|
+
*/
|
|
317
|
+
build(routeToFiles: Map<string, string[]>, fileExtractions: Map<string, CSSExtractionResult>): Map<string, string[]>;
|
|
318
|
+
}
|
|
319
|
+
import { SourceFile as SourceFile6 } from "ts-morph";
|
|
320
|
+
/**
|
|
321
|
+
* Analyze css() calls for diagnostic issues.
|
|
322
|
+
*/
|
|
323
|
+
declare class CSSDiagnostics {
|
|
324
|
+
analyze(sourceFile: SourceFile6): CompilerDiagnostic[];
|
|
325
|
+
/** Validate a single shorthand string. */
|
|
326
|
+
private validateShorthand;
|
|
327
|
+
/** Validate a color token value. */
|
|
328
|
+
private validateColorToken;
|
|
329
|
+
}
|
|
330
|
+
import { SourceFile as SourceFile7 } from "ts-morph";
|
|
331
|
+
/**
|
|
332
|
+
* Detect mutations on `const` variables that are referenced in JSX.
|
|
333
|
+
* These are likely bugs — the user probably meant to use `let`.
|
|
334
|
+
*/
|
|
335
|
+
declare class MutationDiagnostics {
|
|
336
|
+
analyze(sourceFile: SourceFile7, component: ComponentInfo, variables: VariableInfo[]): CompilerDiagnostic[];
|
|
337
|
+
}
|
|
338
|
+
import { SourceFile as SourceFile8 } from "ts-morph";
|
|
339
|
+
/**
|
|
340
|
+
* Warn when component props are destructured in the parameter.
|
|
341
|
+
* Destructuring breaks reactivity because it eagerly reads values.
|
|
342
|
+
*/
|
|
343
|
+
declare class PropsDestructuringDiagnostics {
|
|
344
|
+
analyze(sourceFile: SourceFile8, components: ComponentInfo[]): CompilerDiagnostic[];
|
|
345
|
+
}
|
|
346
|
+
import { SourceFile as SourceFile9 } from "ts-morph";
|
|
347
|
+
/**
|
|
348
|
+
* Detect browser-only API usage at component top level that would crash during SSR.
|
|
349
|
+
*
|
|
350
|
+
* Flags globals like `localStorage`, `navigator`, observer constructors, and
|
|
351
|
+
* browser-only `document` properties when used outside of callbacks (arrow
|
|
352
|
+
* functions, function expressions). Usage inside `onMount()`, event handlers,
|
|
353
|
+
* or any nested function is safe and not flagged.
|
|
354
|
+
*/
|
|
355
|
+
declare class SSRSafetyDiagnostics {
|
|
356
|
+
analyze(sourceFile: SourceFile9, component: ComponentInfo): CompilerDiagnostic[];
|
|
357
|
+
}
|
|
358
|
+
import { BunPlugin } from "bun";
|
|
359
|
+
/** Options for the Vertz library compilation plugin. */
|
|
360
|
+
interface VertzLibraryPluginOptions {
|
|
361
|
+
/** File filter regex. Defaults to /\.tsx$/. */
|
|
362
|
+
filter?: RegExp;
|
|
363
|
+
/** Compilation target. Defaults to 'dom'. */
|
|
364
|
+
target?: "dom" | "tui";
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Creates a Bun plugin for compiling Vertz library packages.
|
|
368
|
+
*
|
|
369
|
+
* Runs hydration transform + compile on .tsx files during bunup build.
|
|
370
|
+
* CSS extraction is intentionally skipped — CSS hashing is path-dependent
|
|
371
|
+
* and must be done by the consuming app's build pipeline.
|
|
372
|
+
*/
|
|
373
|
+
declare function createVertzLibraryPlugin(options?: VertzLibraryPluginOptions): BunPlugin;
|
|
374
|
+
import MagicString from "magic-string";
|
|
375
|
+
import { SourceFile as SourceFile10 } from "ts-morph";
|
|
376
|
+
/**
|
|
377
|
+
* Transform `const x = expr` → `const x = computed(() => expr)` when classified as computed.
|
|
378
|
+
* Also handles destructuring: `const { a, b } = expr` → individual computed declarations.
|
|
379
|
+
*/
|
|
380
|
+
declare class ComputedTransformer {
|
|
381
|
+
transform(source: MagicString, sourceFile: SourceFile10, component: ComponentInfo, variables: VariableInfo[]): void;
|
|
382
|
+
}
|
|
383
|
+
import MagicString2 from "magic-string";
|
|
384
|
+
import { SourceFile as SourceFile11 } from "ts-morph";
|
|
385
|
+
/** Result of CSS transformation. */
|
|
386
|
+
interface CSSTransformResult {
|
|
387
|
+
/** Extracted CSS rules. */
|
|
388
|
+
css: string;
|
|
389
|
+
/** Class name mappings per css() call: call index -> { blockName -> className }. */
|
|
390
|
+
classNameMaps: Map<number, Record<string, string>>;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Transform static css() calls in the source.
|
|
394
|
+
*/
|
|
395
|
+
declare class CSSTransformer {
|
|
396
|
+
transform(s: MagicString2, sourceFile: SourceFile11, cssCalls: CSSCallInfo[], filePath: string): CSSTransformResult;
|
|
397
|
+
/** Process a static css() call to extract CSS and generate class names. */
|
|
398
|
+
private processStaticCall;
|
|
399
|
+
/** Build the replacement JS expression: { card: '_a1b2c3d4', title: '_e5f6g7h8' } */
|
|
400
|
+
private buildReplacement;
|
|
401
|
+
}
|
|
402
|
+
import MagicString3 from "magic-string";
|
|
403
|
+
import { SourceFile as SourceFile12 } from "ts-morph";
|
|
404
|
+
/**
|
|
405
|
+
* Marks interactive components with `data-v-id` hydration markers.
|
|
406
|
+
*
|
|
407
|
+
* A component is "interactive" if it contains `let` variable declarations
|
|
408
|
+
* (reactive state) in its body. Static components (only `const` or no state)
|
|
409
|
+
* are skipped and ship zero JS.
|
|
410
|
+
*
|
|
411
|
+
* For interactive components, the root JSX element's opening tag is augmented
|
|
412
|
+
* with `data-v-id="ComponentName"`.
|
|
413
|
+
*/
|
|
414
|
+
declare class HydrationTransformer {
|
|
415
|
+
transform(s: MagicString3, sourceFile: SourceFile12): void;
|
|
416
|
+
/**
|
|
417
|
+
* Determine whether a component is interactive by checking for `let`
|
|
418
|
+
* declarations in the component body.
|
|
419
|
+
*/
|
|
420
|
+
private _isInteractive;
|
|
421
|
+
/**
|
|
422
|
+
* Find the root JSX element in the component's return statement
|
|
423
|
+
* and inject `data-v-id` attribute into its opening tag.
|
|
424
|
+
*/
|
|
425
|
+
private _addHydrationMarker;
|
|
426
|
+
private _findRootJsx;
|
|
427
|
+
private _injectAttribute;
|
|
428
|
+
}
|
|
429
|
+
import MagicString4 from "magic-string";
|
|
430
|
+
import { SourceFile as SourceFile13 } from "ts-morph";
|
|
431
|
+
/**
|
|
432
|
+
* Transform JSX into DOM helper calls.
|
|
433
|
+
* Reactive expressions are wrapped in functions, static expressions are passed directly.
|
|
434
|
+
*
|
|
435
|
+
* IMPORTANT: This transformer reads expression text from MagicString (via source.slice())
|
|
436
|
+
* so that it picks up .value transforms from the signal/computed transformers.
|
|
437
|
+
*/
|
|
438
|
+
declare class JsxTransformer {
|
|
439
|
+
transform(source: MagicString4, sourceFile: SourceFile13, component: ComponentInfo, variables: VariableInfo[], jsxExpressions: JsxExpressionInfo[]): void;
|
|
440
|
+
/**
|
|
441
|
+
* Walk the full function body and transform every top-level JSX node.
|
|
442
|
+
* "Top-level" means JSX that isn't nested inside other JSX (children are
|
|
443
|
+
* handled recursively by transformJsxNode).
|
|
444
|
+
*/
|
|
445
|
+
private transformAllJsx;
|
|
446
|
+
}
|
|
447
|
+
import MagicString5 from "magic-string";
|
|
448
|
+
/**
|
|
449
|
+
* Transform in-place mutations on signal variables into peek() + notify() pattern.
|
|
450
|
+
*
|
|
451
|
+
* `items.push('x')` → `(items.peek().push('x'), items.notify())`
|
|
452
|
+
* `user.name = "Bob"` → `(user.peek().name = "Bob", user.notify())`
|
|
453
|
+
*/
|
|
454
|
+
declare class MutationTransformer {
|
|
455
|
+
transform(source: MagicString5, _component: ComponentInfo, mutations: MutationInfo[]): void;
|
|
456
|
+
/** `items.push('x')` → `(items.peek().push('x'), items.notify())` */
|
|
457
|
+
private _transformMethodCall;
|
|
458
|
+
/** `user.name = "Bob"` → `(user.peek().name = "Bob", user.notify())` */
|
|
459
|
+
private _transformPropertyAssignment;
|
|
460
|
+
/** `items[0] = 99` → `(items.peek()[0] = 99, items.notify())` */
|
|
461
|
+
private _transformIndexAssignment;
|
|
462
|
+
/** `delete config.debug` → `(delete config.peek().debug, config.notify())` */
|
|
463
|
+
private _transformDelete;
|
|
464
|
+
/** `Object.assign(user, ...)` → `(Object.assign(user.peek(), ...), user.notify())` */
|
|
465
|
+
private _transformObjectAssign;
|
|
466
|
+
}
|
|
467
|
+
import MagicString6 from "magic-string";
|
|
468
|
+
import { Node, SourceFile as SourceFile14 } from "ts-morph";
|
|
469
|
+
/**
|
|
470
|
+
* Transform component props: reactive → getter, static → plain value.
|
|
471
|
+
*
|
|
472
|
+
* This transformer's core logic is integrated into the JsxTransformer's
|
|
473
|
+
* buildPropsObject function. This class exists as a standalone API for
|
|
474
|
+
* cases where prop transformation is needed independently.
|
|
475
|
+
*/
|
|
476
|
+
declare class PropTransformer {
|
|
477
|
+
transform(_source: MagicString6, _sourceFile: SourceFile14, _component: ComponentInfo, _variables: VariableInfo[], _jsxExpressions: JsxExpressionInfo[]): void;
|
|
478
|
+
/** Build a props object string for a component call. */
|
|
479
|
+
buildPropsObject(attrs: Node[], jsxMap: Map<number, JsxExpressionInfo>): string;
|
|
480
|
+
}
|
|
481
|
+
import MagicString7 from "magic-string";
|
|
482
|
+
import { SourceFile as SourceFile15 } from "ts-morph";
|
|
483
|
+
/**
|
|
484
|
+
* Transform `let x = val` → `const x = signal(val)` and all reads/writes
|
|
485
|
+
* for variables classified as signals.
|
|
486
|
+
*
|
|
487
|
+
* Accepts optional mutation ranges to skip — identifiers within mutation
|
|
488
|
+
* expressions are handled by the MutationTransformer instead.
|
|
489
|
+
*/
|
|
490
|
+
declare class SignalTransformer {
|
|
491
|
+
transform(source: MagicString7, sourceFile: SourceFile15, component: ComponentInfo, variables: VariableInfo[], mutationRanges?: Array<{
|
|
492
|
+
start: number;
|
|
493
|
+
end: number;
|
|
494
|
+
}>): void;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Token-aware CSS properties type generation.
|
|
498
|
+
*
|
|
499
|
+
* Generates a `CSSProperties` interface and a `ThemeTokenVar` union type
|
|
500
|
+
* that knows about the theme's token names. This enables type-safe usage
|
|
501
|
+
* of CSS custom property references like `var(--color-primary-500)`.
|
|
502
|
+
*
|
|
503
|
+
* Usage:
|
|
504
|
+
* ```ts
|
|
505
|
+
* const source = generateCSSProperties(themeInput);
|
|
506
|
+
* // Produces:
|
|
507
|
+
* // type ThemeTokenVar = 'var(--color-primary-500)' | 'var(--color-background)' | ...;
|
|
508
|
+
* // export interface CSSProperties {
|
|
509
|
+
* // color?: ThemeTokenVar | string;
|
|
510
|
+
* // backgroundColor?: ThemeTokenVar | string;
|
|
511
|
+
* // ...
|
|
512
|
+
* // }
|
|
513
|
+
* ```
|
|
514
|
+
*/
|
|
515
|
+
/** Color tokens: a map of color names to their raw/contextual values. */
|
|
516
|
+
type ColorTokens = Record<string, Record<string, string>>;
|
|
517
|
+
/** Spacing tokens: a flat map of names to CSS values. */
|
|
518
|
+
type SpacingTokens = Record<string, string>;
|
|
519
|
+
/** Theme input matching defineTheme() input shape. */
|
|
520
|
+
interface CSSPropertiesInput {
|
|
521
|
+
colors: ColorTokens;
|
|
522
|
+
spacing?: SpacingTokens;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Generate TypeScript source for a token-aware CSSProperties interface.
|
|
526
|
+
*
|
|
527
|
+
* @param input - Theme token definitions (same shape as defineTheme input).
|
|
528
|
+
* @returns TypeScript source string with ThemeTokenVar type and CSSProperties interface.
|
|
529
|
+
*/
|
|
530
|
+
declare function generateCSSProperties(input: CSSPropertiesInput): string;
|
|
531
|
+
/**
|
|
532
|
+
* Theme type generation.
|
|
533
|
+
*
|
|
534
|
+
* Generates TypeScript type definitions from a theme input,
|
|
535
|
+
* producing a `ThemeTokens` type with all resolved token paths
|
|
536
|
+
* as string-typed keys.
|
|
537
|
+
*
|
|
538
|
+
* Usage:
|
|
539
|
+
* ```ts
|
|
540
|
+
* const source = generateThemeTypes(themeInput);
|
|
541
|
+
* // Produces:
|
|
542
|
+
* // export type ThemeTokens = {
|
|
543
|
+
* // 'primary.500': string;
|
|
544
|
+
* // 'background': string;
|
|
545
|
+
* // };
|
|
546
|
+
* ```
|
|
547
|
+
*/
|
|
548
|
+
/** Color tokens: a map of color names to their raw/contextual values. */
|
|
549
|
+
type ColorTokens2 = Record<string, Record<string, string>>;
|
|
550
|
+
/** Spacing tokens: a flat map of names to CSS values. */
|
|
551
|
+
type SpacingTokens2 = Record<string, string>;
|
|
552
|
+
/** Theme input matching defineTheme() input shape. */
|
|
553
|
+
interface ThemeTypeInput {
|
|
554
|
+
colors: ColorTokens2;
|
|
555
|
+
spacing?: SpacingTokens2;
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Generate TypeScript source for a ThemeTokens type from a theme definition.
|
|
559
|
+
*
|
|
560
|
+
* @param input - Theme token definitions (same shape as defineTheme input).
|
|
561
|
+
* @returns TypeScript source string with exported ThemeTokens type.
|
|
562
|
+
*/
|
|
563
|
+
declare function generateThemeTypes(input: ThemeTypeInput): string;
|
|
564
|
+
export { generateThemeTypes, generateCSSProperties, createVertzLibraryPlugin, compile, VertzLibraryPluginOptions, VariableInfo, ThemeTypeInput, SignalTransformer, SSRSafetyDiagnostics, RouteCSSManifest, ReactivityKind, ReactivityAnalyzer, PropsDestructuringDiagnostics, PropTransformer, MutationTransformer, MutationKind, MutationInfo, MutationDiagnostics, MutationAnalyzer, JsxTransformer, JsxExpressionInfo, JsxAnalyzer, HydrationTransformer, DiagnosticSeverity, DeadCSSEliminator, ComputedTransformer, ComponentInfo, ComponentAnalyzer, CompilerDiagnostic, CompileOutput, CompileOptions, CSSTransformer, CSSTransformResult, CSSPropertiesInput, CSSHMRUpdateResult, CSSHMRHandler, CSSExtractor, CSSExtractionResult, CSSDiagnostics, CSSCodeSplitter, CSSCallKind, CSSCallInfo, CSSAnalyzer };
|