pudui 0.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.
@@ -0,0 +1,150 @@
1
+ //#region src/transforms.d.ts
2
+ type HydrateCall = {
3
+ end: number;
4
+ exportName: string;
5
+ start: number;
6
+ };
7
+ type EntryCall = {
8
+ end: number;
9
+ start: number;
10
+ };
11
+ /**
12
+ * Mode-specific options for transforming `pudui/macros` calls.
13
+ */
14
+ type TransformHydrateOptions = {
15
+ /**
16
+ * Removes macro calls from client build output.
17
+ */
18
+ mode: "client";
19
+ } | {
20
+ /**
21
+ * Browser entry module used for hydrated client bundles.
22
+ */
23
+ browserEntry: string;
24
+ /**
25
+ * Creates a serializable marker for an entry macro call.
26
+ */
27
+ createEntryMarker(id: string): string;
28
+ /**
29
+ * Creates a serializable marker for a hydrate macro call.
30
+ */
31
+ createHydrateMarker(id: string, exportName: string): string;
32
+ /**
33
+ * Replaces macro calls with build markers for later manifest resolution.
34
+ */
35
+ mode: "build";
36
+ } | {
37
+ /**
38
+ * Browser entry module used for development hydration.
39
+ */
40
+ browserEntry?: string;
41
+ /**
42
+ * Browser-served path for the development entry module.
43
+ */
44
+ browserEntryPath?: string;
45
+ /**
46
+ * JavaScript expression that evaluates to entry stylesheet URLs.
47
+ */
48
+ entryStylesExpression?: string;
49
+ /**
50
+ * Replaces macro calls with development-time metadata.
51
+ */
52
+ mode: "dev";
53
+ /**
54
+ * Browser-served path for the transformed module.
55
+ */
56
+ modulePath: string;
57
+ };
58
+ /**
59
+ * Result of transforming `hydrate()` and `entry()` macro calls.
60
+ */
61
+ type HydrateTransformResult = {
62
+ /**
63
+ * Transformed JavaScript source.
64
+ */
65
+ code: string;
66
+ /**
67
+ * Source ranges for transformed `entry()` calls.
68
+ */
69
+ entryCalls: EntryCall[];
70
+ /**
71
+ * Source ranges for transformed `hydrate()` calls.
72
+ */
73
+ hydrateCalls: HydrateCall[];
74
+ /**
75
+ * Source map placeholder.
76
+ */
77
+ map: null;
78
+ };
79
+ /**
80
+ * Result of transforming a `"use client"` module.
81
+ */
82
+ type UseClientTransformResult = {
83
+ /**
84
+ * Transformed JavaScript source.
85
+ */
86
+ code: string;
87
+ /**
88
+ * Source ranges for component option objects that received `hydrate()`.
89
+ */
90
+ componentOptions: Array<{
91
+ end: number;
92
+ start: number;
93
+ }>;
94
+ /**
95
+ * Source map placeholder.
96
+ */
97
+ map: null;
98
+ };
99
+ /**
100
+ * Injects hydration macros into exported components in a `"use client"` module.
101
+ *
102
+ * The transform looks for exported component factories that create
103
+ * `new Component({ ... })` and appends `hydrate: hydrate()` when needed.
104
+ *
105
+ * @param code Module source code.
106
+ * @param id Stable module identifier used for parsing diagnostics.
107
+ * @returns Transform result, or `null` when the module does not need changes.
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * const result = transformUseClient('"use client"; export function App() {}', "/src/app.tsx");
112
+ * ```
113
+ */
114
+ declare function transformUseClient(code: string, id: string): UseClientTransformResult | null;
115
+ /**
116
+ * Replaces `hydrate()` and `entry()` macro calls with runtime metadata.
117
+ *
118
+ * This is the lower-level transform used by the Vite plugin. Applications
119
+ * usually import the macros from `pudui/macros` and let the plugin call this.
120
+ *
121
+ * @param code Module source code.
122
+ * @param id Stable module identifier used in hydration metadata.
123
+ * @param options Mode-specific transform options.
124
+ * @returns Transform result, or `null` when the module does not use macros.
125
+ */
126
+ declare function transformHydrate(code: string, id: string, options: TransformHydrateOptions): HydrateTransformResult | null;
127
+ /**
128
+ * Replaces build-time hydration marker calls with manifest-derived metadata.
129
+ *
130
+ * @param code Generated bundle code containing marker calls.
131
+ * @param resolveMarker Function that maps marker strings to replacement arrays.
132
+ * @returns Code with resolved marker calls replaced by JSON arrays.
133
+ */
134
+ declare function replaceHydrateMarkers(code: string, resolveMarker: (marker: string) => readonly unknown[] | undefined): string;
135
+ /**
136
+ * Quickly checks whether source may contain Pudui macro calls.
137
+ *
138
+ * @param code Module source code.
139
+ * @returns `true` when the source should be parsed for `hydrate()` or `entry()` macros.
140
+ */
141
+ declare function shouldTransformHydrate(code: string): boolean;
142
+ /**
143
+ * Quickly checks whether source may contain `"use client"` components.
144
+ *
145
+ * @param code Module source code.
146
+ * @returns `true` when the source should be parsed by {@link transformUseClient}.
147
+ */
148
+ declare function shouldTransformUseClient(code: string): boolean;
149
+ //#endregion
150
+ export { HydrateTransformResult, TransformHydrateOptions, UseClientTransformResult, replaceHydrateMarkers, shouldTransformHydrate, shouldTransformUseClient, transformHydrate, transformUseClient };
@@ -0,0 +1,2 @@
1
+ import { a as transformUseClient, i as transformHydrate, n as shouldTransformHydrate, r as shouldTransformUseClient, t as replaceHydrateMarkers } from "./transforms-DUsCAPAL.mjs";
2
+ export { replaceHydrateMarkers, shouldTransformHydrate, shouldTransformUseClient, transformHydrate, transformUseClient };
@@ -0,0 +1,224 @@
1
+ import { HydrateTransformResult, UseClientTransformResult, replaceHydrateMarkers, transformHydrate, transformUseClient } from "./transforms.mjs";
2
+
3
+ //#region src/hmr-transform.d.ts
4
+ /**
5
+ * Options for the Pudui component HMR source transform.
6
+ */
7
+ type HmrTransformOptions = {
8
+ /**
9
+ * Expression used to access the module hot context.
10
+ */
11
+ importMeta?: string;
12
+ /**
13
+ * Parameter name injected into transformed component setup functions.
14
+ */
15
+ refreshParameterName?: string;
16
+ /**
17
+ * Module specifier for the HMR runtime import.
18
+ */
19
+ runtimeModule?: string;
20
+ /**
21
+ * Local binding name for the imported HMR runtime namespace.
22
+ */
23
+ runtimeName?: string;
24
+ };
25
+ //#endregion
26
+ //#region src/transforms/types.d.ts
27
+ /**
28
+ * Configuration for the Pudui Vite plugin.
29
+ */
30
+ type Options = {
31
+ /**
32
+ * Browser entry module that starts client-side hydration.
33
+ *
34
+ * The plugin adds this entry to client builds and uses it to resolve
35
+ * hydration metadata for server-rendered boundaries.
36
+ */
37
+ browserEntry: string;
38
+ /**
39
+ * Hot module replacement settings.
40
+ *
41
+ * Set to `false` to disable Pudui component refresh transforms.
42
+ */
43
+ hmr?: false | HmrTransformOptions;
44
+ };
45
+ /**
46
+ * Minimal Vite resolved config shape used by Pudui transforms.
47
+ */
48
+ type ViteResolvedConfig = {
49
+ base?: string;
50
+ command?: "build" | "serve";
51
+ root: string;
52
+ };
53
+ /**
54
+ * Minimal Vite environment shape used by Pudui transforms.
55
+ */
56
+ type ViteEnvironment = {
57
+ mode?: "build" | "dev";
58
+ name?: string;
59
+ };
60
+ /**
61
+ * Minimal Vite build environment shape used by Pudui build hooks.
62
+ */
63
+ type BuildEnvironment = {
64
+ config: {
65
+ build: {
66
+ emitAssets?: boolean;
67
+ outDir?: string;
68
+ rolldownOptions: {
69
+ input?: string[];
70
+ preserveEntrySignatures?: false | "allow-extension" | "exports-only" | "strict";
71
+ };
72
+ };
73
+ };
74
+ isBuilt: boolean;
75
+ name: string;
76
+ };
77
+ /**
78
+ * Module resolution result returned by Vite's plugin context.
79
+ */
80
+ type ResolveResult = {
81
+ id: string;
82
+ };
83
+ /**
84
+ * Minimal transform context passed to Pudui transform hooks.
85
+ */
86
+ type TransformContext = {
87
+ environment?: ViteEnvironment;
88
+ resolve?(source: string, importer?: string, options?: {
89
+ skipSelf?: boolean;
90
+ }): Promise<ResolveResult | null>;
91
+ };
92
+ /**
93
+ * Minimal Vite builder shape used by the Pudui macro plugin.
94
+ */
95
+ type ViteBuilder = {
96
+ build(environment: BuildEnvironment): Promise<unknown>;
97
+ environments: Record<string, BuildEnvironment>;
98
+ };
99
+ /**
100
+ * Minimal generate-bundle context used by Pudui build hooks.
101
+ */
102
+ type GenerateBundleContext = {
103
+ environment?: ViteEnvironment;
104
+ };
105
+ /**
106
+ * Output bundle map produced by Vite or Rolldown.
107
+ */
108
+ type OutputBundle = Record<string, OutputAsset | OutputChunk>;
109
+ /**
110
+ * Emitted asset in a build output bundle.
111
+ */
112
+ type OutputAsset = {
113
+ fileName: string;
114
+ source?: string | Uint8Array;
115
+ type: "asset";
116
+ };
117
+ /**
118
+ * Emitted chunk in a build output bundle.
119
+ */
120
+ type OutputChunk = {
121
+ code: string;
122
+ fileName: string;
123
+ imports: string[];
124
+ type: "chunk";
125
+ };
126
+ /**
127
+ * Environment-level Vite options returned by Pudui plugins.
128
+ */
129
+ type EnvironmentOptions = {
130
+ build?: {
131
+ emitAssets?: boolean;
132
+ manifest?: boolean | string;
133
+ };
134
+ };
135
+ /**
136
+ * Minimal Vite plugin contract used by Pudui.
137
+ */
138
+ type Plugin = {
139
+ buildApp?: ((builder: ViteBuilder) => Promise<void>) | {
140
+ handler(builder: ViteBuilder): Promise<void>;
141
+ order?: "pre" | "post";
142
+ };
143
+ configEnvironment?(name: string, config: EnvironmentOptions): EnvironmentOptions | void;
144
+ configResolved?(config: ViteResolvedConfig): void;
145
+ enforce?: "pre" | "post";
146
+ generateBundle?: ((this: GenerateBundleContext, options: unknown, bundle: OutputBundle) => void) | {
147
+ handler(this: GenerateBundleContext, options: unknown, bundle: OutputBundle): void;
148
+ order?: "pre" | "post";
149
+ };
150
+ name: string;
151
+ sharedDuringBuild?: boolean;
152
+ transform?(this: TransformContext, code: string, id: string): Promise<null | string | {
153
+ code: string;
154
+ map: null;
155
+ }> | null | string | {
156
+ code: string;
157
+ map: null;
158
+ };
159
+ };
160
+ /**
161
+ * Vite plugin option value returned by Pudui plugin factories.
162
+ */
163
+ type PluginOption = Plugin | PluginOption[] | false | null | undefined;
164
+ //#endregion
165
+ //#region src/vite-plugin.d.ts
166
+ /**
167
+ * Creates the full Pudui Vite plugin set.
168
+ *
169
+ * The returned plugins transform `"use client"` components, replace
170
+ * `pudui/macros` calls, wire build manifest assets, and enable component HMR in
171
+ * development.
172
+ *
173
+ * @param options Pudui Vite plugin options.
174
+ * @returns Vite plugins required for Pudui applications.
175
+ *
176
+ * @example
177
+ * ```ts
178
+ * import { defineConfig } from "vite";
179
+ * import pudui from "pudui/vite-plugin";
180
+ *
181
+ * export default defineConfig({
182
+ * plugins: [pudui({ browserEntry: "app/browser.tsx" })],
183
+ * });
184
+ * ```
185
+ */
186
+ declare function pudui(options: Options): Plugin[];
187
+ /**
188
+ * Creates the transform that injects hydration macros for `"use client"` modules.
189
+ *
190
+ * Most applications should use the default {@link pudui} plugin set instead of
191
+ * composing this directly.
192
+ *
193
+ * @returns A Vite plugin that scans client modules for exported components.
194
+ */
195
+ declare function useClientPlugin(): Plugin;
196
+ /**
197
+ * Creates the transform and build hooks that resolve Pudui macros.
198
+ *
199
+ * The plugin replaces `hydrate()` and `entry()` macro calls, adds client build
200
+ * entries for hydrated modules, and copies manifest asset metadata between Vite
201
+ * environments.
202
+ *
203
+ * @param options Pudui Vite plugin options.
204
+ * @param options.browserEntry Browser entry module used for hydrated client bundles.
205
+ * @returns A Vite plugin for macro transformation and build metadata.
206
+ */
207
+ declare function macrosPlugin(options: Options): Plugin;
208
+ /**
209
+ * Creates the Pudui component HMR transform.
210
+ *
211
+ * This is exported for advanced Vite integrations that need to compose Pudui's
212
+ * plugin pieces manually.
213
+ *
214
+ * @param options HMR plugin options.
215
+ * @param options.hmr HMR options, or `false` to disable the transform.
216
+ * @returns A Vite plugin that rewrites components for refresh.
217
+ */
218
+ declare function hrmPlugin(options?: Pick<Options, "hmr">): Plugin;
219
+ /**
220
+ * Alias for {@link hrmPlugin}.
221
+ */
222
+ declare const hmrPlugin: typeof hrmPlugin;
223
+ //#endregion
224
+ export { type HydrateTransformResult, type Options, type PluginOption, type UseClientTransformResult, pudui as default, hmrPlugin, hrmPlugin, macrosPlugin, replaceHydrateMarkers, transformHydrate, transformUseClient, useClientPlugin };