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.
- package/README.md +161 -0
- package/dist/component-D3kwgmef.mjs +275 -0
- package/dist/core-Cypb6mR9.d.mts +434 -0
- package/dist/hmr-runtime.d.mts +99 -0
- package/dist/hmr-runtime.mjs +177 -0
- package/dist/hydration-markers-DdjOvH6g.mjs +218 -0
- package/dist/index.d.mts +109 -0
- package/dist/index.mjs +1505 -0
- package/dist/jsx-dev-runtime.d.mts +36 -0
- package/dist/jsx-dev-runtime.mjs +2 -0
- package/dist/jsx-runtime.d.mts +36 -0
- package/dist/jsx-runtime.mjs +2 -0
- package/dist/macros.d.mts +43 -0
- package/dist/macros.mjs +47 -0
- package/dist/server.d.mts +55 -0
- package/dist/server.mjs +223 -0
- package/dist/transforms-DUsCAPAL.mjs +707 -0
- package/dist/transforms.d.mts +150 -0
- package/dist/transforms.mjs +2 -0
- package/dist/vite-plugin.d.mts +224 -0
- package/dist/vite-plugin.mjs +748 -0
- package/dist/vite-runtime.d.mts +42 -0
- package/dist/vite-runtime.mjs +89 -0
- package/dist/vnode-Lr-Tpypk.mjs +182 -0
- package/package.json +99 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
//#region src/core/vnode.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Returns its children without adding a wrapper element.
|
|
4
|
+
*
|
|
5
|
+
* This is the fragment implementation used by the JSX runtimes.
|
|
6
|
+
*
|
|
7
|
+
* @param props Fragment props.
|
|
8
|
+
* @returns The fragment children, or `null` when no children were provided.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <>
|
|
13
|
+
* <title>Dashboard</title>
|
|
14
|
+
* <meta name="description" content="Operations dashboard" />
|
|
15
|
+
* </>
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare function Fragment(props: {
|
|
19
|
+
children?: Child;
|
|
20
|
+
}): Child;
|
|
21
|
+
/**
|
|
22
|
+
* Renders trusted HTML without escaping.
|
|
23
|
+
*
|
|
24
|
+
* Prefer normal JSX children whenever possible. Raw HTML is intended for HTML
|
|
25
|
+
* that has already been sanitized or generated by a trusted renderer.
|
|
26
|
+
*
|
|
27
|
+
* @param props Raw HTML props.
|
|
28
|
+
* @returns A raw child that renders its HTML verbatim.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```tsx
|
|
32
|
+
* <Raw>{"<span data-source=\"cms\">Published</span>"}</Raw>
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function Raw(props: RawProps): RawChild;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a Pudui child using the classic JSX factory shape.
|
|
38
|
+
*
|
|
39
|
+
* Most applications use JSX and do not call this directly. It is exported for
|
|
40
|
+
* explicit factory configuration and low-level integrations.
|
|
41
|
+
*
|
|
42
|
+
* @param type Intrinsic tag name, component factory, {@link Fragment}, or {@link Raw}.
|
|
43
|
+
* @param rawProps Props to pass to the render target.
|
|
44
|
+
* @param children Children supplied after the props argument.
|
|
45
|
+
* @returns A renderable child value.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```tsx
|
|
49
|
+
* const child = createElement("button", { type: "button" }, "Save");
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
declare function createElement<Props extends AnyProps>(type: ElementType<Props>, rawProps?: (Props & IntrinsicElementProps) | null, ...children: Child[]): Child;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a Pudui child using the automatic JSX runtime shape.
|
|
55
|
+
*
|
|
56
|
+
* This function is called by compilers configured for
|
|
57
|
+
* `jsxImportSource: "pudui"`.
|
|
58
|
+
*
|
|
59
|
+
* @param type Intrinsic tag name, component factory, {@link Fragment}, or {@link Raw}.
|
|
60
|
+
* @param props Props supplied by the JSX transform.
|
|
61
|
+
* @param key Optional key supplied by the JSX transform.
|
|
62
|
+
* @returns A renderable child value.
|
|
63
|
+
*/
|
|
64
|
+
declare function jsx<Props extends AnyProps>(type: ElementType<Props>, props?: (Props & IntrinsicElementProps) | null, key?: Key): Child;
|
|
65
|
+
/**
|
|
66
|
+
* Development JSX runtime entry compatible with React's `jsxDEV` call shape.
|
|
67
|
+
*/
|
|
68
|
+
declare const jsxDEV: <Props extends AnyProps>(type: ElementType<Props>, props?: (Props & IntrinsicElementProps) | null, key?: Key, _isStaticChildren?: boolean, _source?: unknown, _self?: unknown) => Child;
|
|
69
|
+
/**
|
|
70
|
+
* Checks whether a value is a Pudui virtual node.
|
|
71
|
+
*
|
|
72
|
+
* @param value Value to inspect.
|
|
73
|
+
* @returns `true` when the value is a virtual node created by Pudui's JSX runtime.
|
|
74
|
+
*/
|
|
75
|
+
declare function isVNode(value: unknown): value is VNode;
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/core/component.d.ts
|
|
78
|
+
/**
|
|
79
|
+
* Stateful unit of rendering in Pudui.
|
|
80
|
+
*
|
|
81
|
+
* Components own their render function, mount callbacks, child component
|
|
82
|
+
* instances, and update scheduling. Create components from JSX factories and
|
|
83
|
+
* call {@link update} when internal state changes.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```tsx
|
|
87
|
+
* import { Component, event } from "pudui";
|
|
88
|
+
*
|
|
89
|
+
* export function Counter() {
|
|
90
|
+
* let count = 0;
|
|
91
|
+
* const counter = new Component({
|
|
92
|
+
* render() {
|
|
93
|
+
* return <button ref={event("click", () => { count++; counter.update(); })}>{count}</button>;
|
|
94
|
+
* },
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* return counter;
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
declare class Component<Props extends AnyProps = AnyProps> {
|
|
102
|
+
/**
|
|
103
|
+
* Creates a component from render options.
|
|
104
|
+
*
|
|
105
|
+
* @param options Render, error, and hydration options for this component.
|
|
106
|
+
*/
|
|
107
|
+
constructor(options: ComponentOptions<Props>);
|
|
108
|
+
/**
|
|
109
|
+
* Queues a callback to run after the component's first browser mount.
|
|
110
|
+
*
|
|
111
|
+
* If the component is already mounted, the callback is ignored.
|
|
112
|
+
*
|
|
113
|
+
* @param callback Function to run after the initial mount commits.
|
|
114
|
+
*/
|
|
115
|
+
mount(callback: MountCallback): void;
|
|
116
|
+
/**
|
|
117
|
+
* Schedules this component to rerender.
|
|
118
|
+
*
|
|
119
|
+
* Multiple updates in the same turn are batched. The optional callback runs
|
|
120
|
+
* after the update commits, unless the root has been unmounted.
|
|
121
|
+
*
|
|
122
|
+
* @param callback Function to run after the update commits.
|
|
123
|
+
*/
|
|
124
|
+
update(callback?: UpdateCallback): void;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Checks whether a value is a Pudui component instance.
|
|
128
|
+
*
|
|
129
|
+
* @param value Value to inspect.
|
|
130
|
+
* @returns `true` when the value is a {@link Component}.
|
|
131
|
+
*/
|
|
132
|
+
declare function isComponent(value: unknown): value is Component;
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/core.d.ts
|
|
135
|
+
/**
|
|
136
|
+
* Stable identity used to reconcile siblings across renders.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```tsx
|
|
140
|
+
* items.map((item) => <li key={item.id}>{item.name}</li>);
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
type Key = string | number;
|
|
144
|
+
/**
|
|
145
|
+
* A child value that intentionally renders no markup.
|
|
146
|
+
*
|
|
147
|
+
* Empty children are useful for conditional JSX where one branch should
|
|
148
|
+
* disappear without leaving a text node.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```tsx
|
|
152
|
+
* <nav>{isSignedIn && <a href="/account">Account</a>}</nav>
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
type EmptyChild = boolean | null | undefined;
|
|
156
|
+
/**
|
|
157
|
+
* A scalar value that renders as escaped text.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```tsx
|
|
161
|
+
* <span>{messageCount}</span>
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
type PrimitiveChild = string | number | bigint;
|
|
165
|
+
/**
|
|
166
|
+
* Trusted HTML that should be inserted without escaping.
|
|
167
|
+
*
|
|
168
|
+
* Create raw children with the {@link Raw} component instead of constructing
|
|
169
|
+
* this object by hand.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```tsx
|
|
173
|
+
* <Raw>{"<strong>Already escaped upstream</strong>"}</Raw>
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
type RawChild = {
|
|
177
|
+
readonly r: true;
|
|
178
|
+
readonly h: string;
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Props accepted by {@link Raw}.
|
|
182
|
+
*/
|
|
183
|
+
type RawProps = {
|
|
184
|
+
/**
|
|
185
|
+
* Trusted HTML to render verbatim.
|
|
186
|
+
*/
|
|
187
|
+
children?: string;
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Callback that runs after a scheduled component update commits.
|
|
191
|
+
*/
|
|
192
|
+
type UpdateCallback = (this: void) => void;
|
|
193
|
+
/**
|
|
194
|
+
* The public instance contract shared by stateful Pudui components.
|
|
195
|
+
*/
|
|
196
|
+
type ComponentInstance = {
|
|
197
|
+
/**
|
|
198
|
+
* Schedules the component to rerender.
|
|
199
|
+
*
|
|
200
|
+
* @param callback Function to run after the update commits.
|
|
201
|
+
*/
|
|
202
|
+
update(callback?: UpdateCallback): void;
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Any value that can be rendered by Pudui.
|
|
206
|
+
*
|
|
207
|
+
* Children may be nested arrays. Pudui flattens arrays and drops empty
|
|
208
|
+
* children during rendering.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```tsx
|
|
212
|
+
* const title: Child = ["Hello ", <strong>world</strong>];
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
type Child = ComponentInstance | EmptyChild | PrimitiveChild | RawChild | VNode | readonly Child[];
|
|
216
|
+
/**
|
|
217
|
+
* Base constraint for component props.
|
|
218
|
+
*/
|
|
219
|
+
type AnyProps = object;
|
|
220
|
+
/**
|
|
221
|
+
* A component factory that receives its initial props.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```tsx
|
|
225
|
+
* const Counter: ComponentFactoryWithProps<{ start: number }> = (props) =>
|
|
226
|
+
* new Component({ render: () => <button>{props.start}</button> });
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
type ComponentFactoryWithProps<Props extends AnyProps = AnyProps> = (initialProps: Readonly<Props>) => Component<Props>;
|
|
230
|
+
/**
|
|
231
|
+
* A component factory that does not require initial props.
|
|
232
|
+
*/
|
|
233
|
+
type ComponentFactoryWithoutProps<Props extends AnyProps = AnyProps> = () => Component<Props>;
|
|
234
|
+
/**
|
|
235
|
+
* A function component constructor used as a JSX tag.
|
|
236
|
+
*/
|
|
237
|
+
type ComponentFactory<Props extends AnyProps = AnyProps> = ComponentFactoryWithProps<Props> | ComponentFactoryWithoutProps<Props>;
|
|
238
|
+
/**
|
|
239
|
+
* A JSX tag target: either an intrinsic element name or a component factory.
|
|
240
|
+
*/
|
|
241
|
+
type RenderableType<Props extends AnyProps = AnyProps> = string | ComponentFactory<Props>;
|
|
242
|
+
/**
|
|
243
|
+
* Assets that should be preloaded before hydrating a component boundary.
|
|
244
|
+
*/
|
|
245
|
+
type PreloadMetadata = {
|
|
246
|
+
/**
|
|
247
|
+
* JavaScript module URLs to emit as module preload links.
|
|
248
|
+
*/
|
|
249
|
+
modulePreloads?: readonly string[];
|
|
250
|
+
/**
|
|
251
|
+
* Stylesheet URLs to emit as preload links.
|
|
252
|
+
*/
|
|
253
|
+
stylePreloads?: readonly string[];
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Resolves build-time hydration metadata into preloadable assets.
|
|
257
|
+
*
|
|
258
|
+
* Return `null` or `undefined` when the metadata cannot be resolved.
|
|
259
|
+
*/
|
|
260
|
+
type PreloadResolver = (meta: unknown) => PreloadMetadata | null | undefined;
|
|
261
|
+
/**
|
|
262
|
+
* Any value that can appear in the JSX tag position.
|
|
263
|
+
*/
|
|
264
|
+
type ElementType<Props extends AnyProps = AnyProps> = RenderableType<Props> | typeof Fragment | typeof Raw;
|
|
265
|
+
/**
|
|
266
|
+
* Object form for a JSX `style` prop.
|
|
267
|
+
*
|
|
268
|
+
* Values are serialized as CSS declarations, and `null` or `undefined` values
|
|
269
|
+
* are skipped.
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* ```tsx
|
|
273
|
+
* <button style={{ backgroundColor: "black", opacity: disabled ? 0.5 : 1 }} />
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
type StyleValue = Record<string, number | string | null | undefined>;
|
|
277
|
+
/**
|
|
278
|
+
* Escaped hatch for setting an element's `innerHTML`.
|
|
279
|
+
*
|
|
280
|
+
* Prefer regular children. Use this only for trusted HTML.
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```tsx
|
|
284
|
+
* <div dangerouslySetInnerHTML={{ __html: trustedHtml }} />
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
type DangerouslySetInnerHTML = {
|
|
288
|
+
__html: string;
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* Cleanup returned by a ref callback.
|
|
292
|
+
*/
|
|
293
|
+
type RefCleanup = () => void;
|
|
294
|
+
/**
|
|
295
|
+
* Callback ref invoked when an element is connected.
|
|
296
|
+
*
|
|
297
|
+
* Return a cleanup to run when the element is removed or replaced.
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```tsx
|
|
301
|
+
* <input ref={(input) => {
|
|
302
|
+
* input.focus();
|
|
303
|
+
* return () => console.log("input removed");
|
|
304
|
+
* }} />
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
type RefCallback<ElementType = Element> = (element: ElementType) => void | RefCleanup;
|
|
308
|
+
/**
|
|
309
|
+
* A ref callback or a nested list of ref callbacks.
|
|
310
|
+
*/
|
|
311
|
+
type RefValue<ElementType = Element> = RefCallback<ElementType> | readonly RefValue<ElementType>[];
|
|
312
|
+
/**
|
|
313
|
+
* Callback queued with {@link Component.mount}.
|
|
314
|
+
*/
|
|
315
|
+
type MountCallback = (this: void) => void;
|
|
316
|
+
type UnsupportedEventAttributes = { [Name in `on${string}`]?: never };
|
|
317
|
+
/**
|
|
318
|
+
* Props accepted by intrinsic JSX elements.
|
|
319
|
+
*
|
|
320
|
+
* Event attributes such as `onClick` are intentionally unsupported. Use the
|
|
321
|
+
* {@link event} helper from `pudui` with a `ref` when wiring DOM events.
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```tsx
|
|
325
|
+
* <button class="primary" ref={event("click", onClick)}>Save</button>
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
328
|
+
type IntrinsicElementProps<ElementType = Element> = UnsupportedEventAttributes & {
|
|
329
|
+
/**
|
|
330
|
+
* Element children.
|
|
331
|
+
*/
|
|
332
|
+
children?: Child;
|
|
333
|
+
/**
|
|
334
|
+
* HTML class attribute.
|
|
335
|
+
*/
|
|
336
|
+
class?: string;
|
|
337
|
+
/**
|
|
338
|
+
* Alias for the HTML class attribute.
|
|
339
|
+
*/
|
|
340
|
+
className?: string;
|
|
341
|
+
/**
|
|
342
|
+
* Trusted HTML to set as element contents.
|
|
343
|
+
*/
|
|
344
|
+
dangerouslySetInnerHTML?: DangerouslySetInnerHTML;
|
|
345
|
+
/**
|
|
346
|
+
* Stable identity for component and element reconciliation.
|
|
347
|
+
*/
|
|
348
|
+
key?: Key;
|
|
349
|
+
/**
|
|
350
|
+
* Ref callback or callbacks for the rendered element.
|
|
351
|
+
*/
|
|
352
|
+
ref?: RefValue<ElementType>;
|
|
353
|
+
/**
|
|
354
|
+
* Object-form inline style declarations.
|
|
355
|
+
*/
|
|
356
|
+
style?: StyleValue;
|
|
357
|
+
[name: string]: unknown;
|
|
358
|
+
};
|
|
359
|
+
/**
|
|
360
|
+
* Infers a component's declared props when JSX type checking a tag.
|
|
361
|
+
*/
|
|
362
|
+
type ComponentPropsFor<Type, Props> = Type extends ((...args: readonly unknown[]) => Component<infer ComponentProps extends AnyProps>) ? ComponentProps : Props;
|
|
363
|
+
/**
|
|
364
|
+
* Intrinsic JSX element map for HTML, SVG, and MathML tag names.
|
|
365
|
+
*/
|
|
366
|
+
type IntrinsicElementsByTagName = { [TagName in keyof HTMLElementTagNameMap]: IntrinsicElementProps<HTMLElementTagNameMap[TagName]> } & { [TagName in Exclude<keyof SVGElementTagNameMap, keyof HTMLElementTagNameMap>]: IntrinsicElementProps<SVGElementTagNameMap[TagName]> } & { [TagName in Exclude<keyof MathMLElementTagNameMap, keyof HTMLElementTagNameMap | keyof SVGElementTagNameMap>]: IntrinsicElementProps<MathMLElementTagNameMap[TagName]> };
|
|
367
|
+
/**
|
|
368
|
+
* Options used to construct a {@link Component}.
|
|
369
|
+
*
|
|
370
|
+
* @example
|
|
371
|
+
* ```tsx
|
|
372
|
+
* const component = new Component({
|
|
373
|
+
* render: () => <p>Hello</p>,
|
|
374
|
+
* });
|
|
375
|
+
* ```
|
|
376
|
+
*/
|
|
377
|
+
type ComponentOptions<Props extends AnyProps> = {
|
|
378
|
+
/**
|
|
379
|
+
* Renders fallback content when {@link render} throws.
|
|
380
|
+
*
|
|
381
|
+
* @param props Current component props.
|
|
382
|
+
* @param reason The thrown error or rejection reason.
|
|
383
|
+
* @returns Fallback child content.
|
|
384
|
+
*/
|
|
385
|
+
error?(this: void, props: Readonly<Props>, reason: unknown): Child;
|
|
386
|
+
/**
|
|
387
|
+
* Metadata consumed by the hydration macros and Vite runtime.
|
|
388
|
+
*/
|
|
389
|
+
hydrate?: unknown;
|
|
390
|
+
/**
|
|
391
|
+
* Renders the component's current child tree.
|
|
392
|
+
*
|
|
393
|
+
* @param props Current component props.
|
|
394
|
+
* @returns Child content for this render pass.
|
|
395
|
+
*/
|
|
396
|
+
render(this: void, props: Readonly<Props>): Child;
|
|
397
|
+
};
|
|
398
|
+
/**
|
|
399
|
+
* Virtual node produced by JSX for host elements and component tags.
|
|
400
|
+
*/
|
|
401
|
+
type VNode<Props extends AnyProps = AnyProps> = {
|
|
402
|
+
/**
|
|
403
|
+
* Host tag name or component factory.
|
|
404
|
+
*/
|
|
405
|
+
readonly type: RenderableType<Props>;
|
|
406
|
+
/**
|
|
407
|
+
* Props captured for the render target.
|
|
408
|
+
*/
|
|
409
|
+
readonly props: Readonly<Props & IntrinsicElementProps>;
|
|
410
|
+
/**
|
|
411
|
+
* Optional reconciliation key.
|
|
412
|
+
*/
|
|
413
|
+
readonly key?: Key;
|
|
414
|
+
};
|
|
415
|
+
declare global {
|
|
416
|
+
namespace JSX {
|
|
417
|
+
type Element = Child;
|
|
418
|
+
interface ElementChildrenAttribute {
|
|
419
|
+
children: unknown;
|
|
420
|
+
}
|
|
421
|
+
type LibraryManagedAttributes<ComponentType, Props> = ComponentPropsFor<ComponentType, Props>;
|
|
422
|
+
interface IntrinsicAttributes {
|
|
423
|
+
key?: Key;
|
|
424
|
+
}
|
|
425
|
+
interface IntrinsicElements extends IntrinsicElementsByTagName {
|
|
426
|
+
[elementName: string]: IntrinsicElementProps<any>;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Internal marker range and props for a server-rendered hydration boundary.
|
|
432
|
+
*/
|
|
433
|
+
//#endregion
|
|
434
|
+
export { Fragment as A, RefValue as C, VNode as D, UpdateCallback as E, jsxDEV as F, createElement as M, isVNode as N, Component as O, jsx as P, RefCleanup as S, StyleValue as T, PreloadResolver as _, ComponentFactoryWithoutProps as a, RawProps as b, ComponentPropsFor as c, EmptyChild as d, IntrinsicElementProps as f, PreloadMetadata as g, MountCallback as h, ComponentFactoryWithProps as i, Raw as j, isComponent as k, DangerouslySetInnerHTML as l, Key as m, Child as n, ComponentInstance as o, IntrinsicElementsByTagName as p, ComponentFactory as r, ComponentOptions as s, AnyProps as t, ElementType as u, PrimitiveChild as v, RenderableType as w, RefCallback as x, RawChild as y };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { O as Component, i as ComponentFactoryWithProps, s as ComponentOptions, t as AnyProps } from "./core-Cypb6mR9.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/hmr-runtime.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Mutable state cell preserved across compatible HMR updates.
|
|
6
|
+
*/
|
|
7
|
+
type RefreshCell<Value> = {
|
|
8
|
+
/**
|
|
9
|
+
* Current cell value.
|
|
10
|
+
*/
|
|
11
|
+
value: Value;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Component options that can be replaced during HMR.
|
|
15
|
+
*/
|
|
16
|
+
type RefreshComponentOptions<Props extends AnyProps> = Pick<ComponentOptions<Props>, "error" | "hydrate" | "render">;
|
|
17
|
+
/**
|
|
18
|
+
* Utilities passed to a transformed component setup function.
|
|
19
|
+
*/
|
|
20
|
+
type RefreshContext<Props extends AnyProps> = {
|
|
21
|
+
/**
|
|
22
|
+
* Reads or initializes a state cell that can survive hot updates.
|
|
23
|
+
*
|
|
24
|
+
* @param key Stable key for this cell within the component.
|
|
25
|
+
* @param initialize Function used to create the cell value the first time.
|
|
26
|
+
* @returns The preserved refresh cell.
|
|
27
|
+
*/
|
|
28
|
+
cell<Value>(key: string, initialize: () => Value): RefreshCell<Value>;
|
|
29
|
+
/**
|
|
30
|
+
* Creates or updates the component instance for this refresh record.
|
|
31
|
+
*
|
|
32
|
+
* @param options Component options for the current module version.
|
|
33
|
+
* @returns The component instance associated with the refresh record.
|
|
34
|
+
*/
|
|
35
|
+
component<ComponentProps extends AnyProps = Props>(options: RefreshComponentOptions<ComponentProps>): Component<ComponentProps>;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Setup function generated by the HMR transform for a component factory.
|
|
39
|
+
*/
|
|
40
|
+
type RefreshSetup<Props extends AnyProps> = (refresh: RefreshContext<Props>, initialProps: Readonly<Props>) => Component<Props>;
|
|
41
|
+
type HmrImportMeta = {
|
|
42
|
+
hot?: {
|
|
43
|
+
data: Record<string, unknown>;
|
|
44
|
+
invalidate?(message?: string): void;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
type RefreshVersion<Props extends AnyProps> = {
|
|
48
|
+
setup: RefreshSetup<Props>;
|
|
49
|
+
signature: string;
|
|
50
|
+
};
|
|
51
|
+
type RefreshInstance<Props extends AnyProps> = {
|
|
52
|
+
cells: Map<string, RefreshCell<unknown>>;
|
|
53
|
+
component?: Component<AnyProps>;
|
|
54
|
+
initialProps: Readonly<Props>;
|
|
55
|
+
lastProps?: Readonly<AnyProps>;
|
|
56
|
+
options?: RefreshComponentOptions<AnyProps>;
|
|
57
|
+
};
|
|
58
|
+
type RefreshFactory<Props extends AnyProps> = ComponentFactoryWithProps<Props> & {
|
|
59
|
+
[recordProperty]?: RefreshRecord<Props>;
|
|
60
|
+
};
|
|
61
|
+
type RefreshRecord<Props extends AnyProps> = RefreshVersion<Props> & {
|
|
62
|
+
exported: boolean;
|
|
63
|
+
exportName: string;
|
|
64
|
+
factory: RefreshFactory<Props>;
|
|
65
|
+
instances: Set<RefreshInstance<Props>>;
|
|
66
|
+
pending?: RefreshVersion<Props>;
|
|
67
|
+
pendingExported?: boolean;
|
|
68
|
+
};
|
|
69
|
+
type RegisterOptions = {
|
|
70
|
+
exported?: boolean;
|
|
71
|
+
};
|
|
72
|
+
declare const recordProperty = "__puduiHmrRecord";
|
|
73
|
+
/**
|
|
74
|
+
* Registers a component factory with the Pudui HMR runtime.
|
|
75
|
+
*
|
|
76
|
+
* This is emitted by the HMR transform. Application code should normally use
|
|
77
|
+
* the Vite plugin rather than calling it directly.
|
|
78
|
+
*
|
|
79
|
+
* @param importMeta Module `import.meta` object.
|
|
80
|
+
* @param id Stable module identifier.
|
|
81
|
+
* @param exportName Name of the export being registered.
|
|
82
|
+
* @param signature Signature for the component's preserved state shape.
|
|
83
|
+
* @param setup Setup function for the current module version.
|
|
84
|
+
* @param options Registration options.
|
|
85
|
+
* @returns A component factory that keeps its refresh record across updates.
|
|
86
|
+
*/
|
|
87
|
+
declare function register<Props extends AnyProps>(importMeta: HmrImportMeta, id: string, exportName: string, signature: string, setup: RefreshSetup<Props>, options?: RegisterOptions): RefreshFactory<Props>;
|
|
88
|
+
/**
|
|
89
|
+
* Accepts a hot module update and refreshes registered components.
|
|
90
|
+
*
|
|
91
|
+
* If an export changed shape in a way Pudui cannot refresh safely, the runtime
|
|
92
|
+
* asks Vite to invalidate the module instead.
|
|
93
|
+
*
|
|
94
|
+
* @param importMeta Module `import.meta` object for the updated module.
|
|
95
|
+
* @param nextModule The next module namespace provided by Vite HMR.
|
|
96
|
+
*/
|
|
97
|
+
declare function accept(importMeta: HmrImportMeta, nextModule: unknown): void;
|
|
98
|
+
//#endregion
|
|
99
|
+
export { RefreshCell, RefreshComponentOptions, RefreshContext, RefreshSetup, accept, register };
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { t as Component } from "./component-D3kwgmef.mjs";
|
|
2
|
+
//#region src/hmr-runtime.ts
|
|
3
|
+
const globalRegistryKey = "__puduiHmrRegistry";
|
|
4
|
+
const moduleDataKey = "__puduiHmr";
|
|
5
|
+
const recordProperty = "__puduiHmrRecord";
|
|
6
|
+
/**
|
|
7
|
+
* Registers a component factory with the Pudui HMR runtime.
|
|
8
|
+
*
|
|
9
|
+
* This is emitted by the HMR transform. Application code should normally use
|
|
10
|
+
* the Vite plugin rather than calling it directly.
|
|
11
|
+
*
|
|
12
|
+
* @param importMeta Module `import.meta` object.
|
|
13
|
+
* @param id Stable module identifier.
|
|
14
|
+
* @param exportName Name of the export being registered.
|
|
15
|
+
* @param signature Signature for the component's preserved state shape.
|
|
16
|
+
* @param setup Setup function for the current module version.
|
|
17
|
+
* @param options Registration options.
|
|
18
|
+
* @returns A component factory that keeps its refresh record across updates.
|
|
19
|
+
*/
|
|
20
|
+
function register(importMeta, id, exportName, signature, setup, options = {}) {
|
|
21
|
+
const moduleData = ensureModuleData(importMeta, id);
|
|
22
|
+
const registryKey = recordKey(id, exportName);
|
|
23
|
+
const exported = options.exported ?? true;
|
|
24
|
+
let record = moduleData?.records.get(exportName) ?? refreshRegistry().get(registryKey);
|
|
25
|
+
if (record === void 0) {
|
|
26
|
+
record = createRecord(exportName, signature, setup, exported);
|
|
27
|
+
refreshRegistry().set(registryKey, record);
|
|
28
|
+
} else if (importMeta.hot) {
|
|
29
|
+
record.pending = {
|
|
30
|
+
setup,
|
|
31
|
+
signature
|
|
32
|
+
};
|
|
33
|
+
record.pendingExported = exported;
|
|
34
|
+
} else {
|
|
35
|
+
record.exported = exported;
|
|
36
|
+
replaceRecord(record, {
|
|
37
|
+
setup,
|
|
38
|
+
signature
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
moduleData?.records.set(exportName, record);
|
|
42
|
+
return record.factory;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Accepts a hot module update and refreshes registered components.
|
|
46
|
+
*
|
|
47
|
+
* If an export changed shape in a way Pudui cannot refresh safely, the runtime
|
|
48
|
+
* asks Vite to invalidate the module instead.
|
|
49
|
+
*
|
|
50
|
+
* @param importMeta Module `import.meta` object for the updated module.
|
|
51
|
+
* @param nextModule The next module namespace provided by Vite HMR.
|
|
52
|
+
*/
|
|
53
|
+
function accept(importMeta, nextModule) {
|
|
54
|
+
const moduleData = readModuleData(importMeta);
|
|
55
|
+
if (moduleData === void 0) return;
|
|
56
|
+
if (!isObject(nextModule)) {
|
|
57
|
+
invalidate(importMeta, `Unable to refresh ${moduleData.id}.`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const updates = [];
|
|
61
|
+
for (const [exportName, record] of moduleData.records) {
|
|
62
|
+
const nextVersion = record.exported ? readRecord(nextModule[exportName])?.pending : record.pending;
|
|
63
|
+
if (nextVersion === void 0) {
|
|
64
|
+
invalidate(importMeta, `Unable to refresh ${moduleData.id} because export "${exportName}" changed shape.`);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
updates.push(() => {
|
|
68
|
+
record.exported = record.pendingExported ?? record.exported;
|
|
69
|
+
replaceRecord(record, nextVersion);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
for (const update of updates) update();
|
|
73
|
+
}
|
|
74
|
+
function createRecord(exportName, signature, setup, exported) {
|
|
75
|
+
let record;
|
|
76
|
+
const factory = ((initialProps) => {
|
|
77
|
+
const props = initialProps ?? {};
|
|
78
|
+
const instance = {
|
|
79
|
+
cells: /* @__PURE__ */ new Map(),
|
|
80
|
+
initialProps: props
|
|
81
|
+
};
|
|
82
|
+
const component = record.setup(createRefreshContext(instance), props);
|
|
83
|
+
if (component !== instance.component) throw new TypeError("Refresh setup must return the Component created through refresh.component().");
|
|
84
|
+
record.instances.add(instance);
|
|
85
|
+
return component;
|
|
86
|
+
});
|
|
87
|
+
record = {
|
|
88
|
+
exported,
|
|
89
|
+
exportName,
|
|
90
|
+
factory,
|
|
91
|
+
instances: /* @__PURE__ */ new Set(),
|
|
92
|
+
setup,
|
|
93
|
+
signature
|
|
94
|
+
};
|
|
95
|
+
Object.defineProperty(factory, recordProperty, { value: record });
|
|
96
|
+
return record;
|
|
97
|
+
}
|
|
98
|
+
function replaceRecord(record, next) {
|
|
99
|
+
const preserveCells = next.signature === record.signature;
|
|
100
|
+
record.pending = void 0;
|
|
101
|
+
record.pendingExported = void 0;
|
|
102
|
+
record.setup = next.setup;
|
|
103
|
+
record.signature = next.signature;
|
|
104
|
+
for (const instance of record.instances) {
|
|
105
|
+
if (!preserveCells) instance.cells.clear();
|
|
106
|
+
if (record.setup(createRefreshContext(instance), instance.lastProps ?? instance.initialProps) !== instance.component) throw new TypeError("Refresh setup must return the Component created through refresh.component().");
|
|
107
|
+
instance.component?.update();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function createRefreshContext(instance) {
|
|
111
|
+
return {
|
|
112
|
+
cell(key, initialize) {
|
|
113
|
+
const existing = instance.cells.get(key);
|
|
114
|
+
if (existing !== void 0) return existing;
|
|
115
|
+
const cell = { value: initialize() };
|
|
116
|
+
instance.cells.set(key, cell);
|
|
117
|
+
return cell;
|
|
118
|
+
},
|
|
119
|
+
component(options) {
|
|
120
|
+
const typedOptions = options;
|
|
121
|
+
instance.options = typedOptions;
|
|
122
|
+
if (instance.component !== void 0) return instance.component;
|
|
123
|
+
const component = new Component({
|
|
124
|
+
error(props, reason) {
|
|
125
|
+
instance.lastProps = props;
|
|
126
|
+
if (instance.options?.error === void 0) throw reason;
|
|
127
|
+
return instance.options.error(props, reason);
|
|
128
|
+
},
|
|
129
|
+
hydrate: typedOptions.hydrate,
|
|
130
|
+
render(props) {
|
|
131
|
+
instance.lastProps = props;
|
|
132
|
+
return instance.options?.render(props) ?? null;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
instance.component = component;
|
|
136
|
+
return component;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function ensureModuleData(importMeta, id) {
|
|
141
|
+
if (!importMeta.hot) return;
|
|
142
|
+
const existing = importMeta.hot.data[moduleDataKey];
|
|
143
|
+
if (isModuleData(existing) && existing.id === id) return existing;
|
|
144
|
+
const moduleData = {
|
|
145
|
+
id,
|
|
146
|
+
records: /* @__PURE__ */ new Map()
|
|
147
|
+
};
|
|
148
|
+
importMeta.hot.data[moduleDataKey] = moduleData;
|
|
149
|
+
return moduleData;
|
|
150
|
+
}
|
|
151
|
+
function readModuleData(importMeta) {
|
|
152
|
+
const value = importMeta.hot?.data[moduleDataKey];
|
|
153
|
+
return isModuleData(value) ? value : void 0;
|
|
154
|
+
}
|
|
155
|
+
function isModuleData(value) {
|
|
156
|
+
return isObject(value) && typeof value.id === "string" && value.records instanceof Map;
|
|
157
|
+
}
|
|
158
|
+
function readRecord(value) {
|
|
159
|
+
if (typeof value !== "function") return;
|
|
160
|
+
return value[recordProperty];
|
|
161
|
+
}
|
|
162
|
+
function refreshRegistry() {
|
|
163
|
+
const root = globalThis;
|
|
164
|
+
root[globalRegistryKey] ??= /* @__PURE__ */ new Map();
|
|
165
|
+
return root[globalRegistryKey];
|
|
166
|
+
}
|
|
167
|
+
function recordKey(id, exportName) {
|
|
168
|
+
return `${id}\u0000${exportName}`;
|
|
169
|
+
}
|
|
170
|
+
function invalidate(importMeta, message) {
|
|
171
|
+
importMeta.hot?.invalidate?.(message);
|
|
172
|
+
}
|
|
173
|
+
function isObject(value) {
|
|
174
|
+
return typeof value === "object" && value !== null;
|
|
175
|
+
}
|
|
176
|
+
//#endregion
|
|
177
|
+
export { accept, register };
|