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,36 @@
1
+ import { A as Fragment, F as jsxDEV, c as ComponentPropsFor, f as IntrinsicElementProps, n as Child, p as IntrinsicElementsByTagName } from "./core-Cypb6mR9.mjs";
2
+
3
+ //#region src/jsx-dev-runtime.d.ts
4
+ /**
5
+ * JSX types for the development Pudui JSX runtime.
6
+ */
7
+ declare namespace JSX {
8
+ /**
9
+ * Any value that can be returned from JSX.
10
+ */
11
+ type Element = Child;
12
+ /**
13
+ * Configures JSX children to use the `children` prop.
14
+ */
15
+ interface ElementChildrenAttribute {
16
+ children: unknown;
17
+ }
18
+ /**
19
+ * Props available on every JSX element.
20
+ */
21
+ interface IntrinsicAttributes {
22
+ key?: string | number;
23
+ }
24
+ /**
25
+ * Infers component props for JSX tags.
26
+ */
27
+ type LibraryManagedAttributes<ComponentType, Props> = ComponentPropsFor<ComponentType, Props>;
28
+ /**
29
+ * Built-in element props for HTML, SVG, MathML, and custom elements.
30
+ */
31
+ interface IntrinsicElements extends IntrinsicElementsByTagName {
32
+ [elementName: string]: IntrinsicElementProps<any>;
33
+ }
34
+ }
35
+ //#endregion
36
+ export { Fragment, JSX, jsxDEV };
@@ -0,0 +1,2 @@
1
+ import { c as jsxDEV, t as Fragment } from "./vnode-Lr-Tpypk.mjs";
2
+ export { Fragment, jsxDEV };
@@ -0,0 +1,36 @@
1
+ import { A as Fragment, P as jsx, c as ComponentPropsFor, f as IntrinsicElementProps, n as Child, p as IntrinsicElementsByTagName } from "./core-Cypb6mR9.mjs";
2
+
3
+ //#region src/jsx-runtime.d.ts
4
+ /**
5
+ * JSX types for the automatic Pudui JSX runtime.
6
+ */
7
+ declare namespace JSX {
8
+ /**
9
+ * Any value that can be returned from JSX.
10
+ */
11
+ type Element = Child;
12
+ /**
13
+ * Configures JSX children to use the `children` prop.
14
+ */
15
+ interface ElementChildrenAttribute {
16
+ children: unknown;
17
+ }
18
+ /**
19
+ * Props available on every JSX element.
20
+ */
21
+ interface IntrinsicAttributes {
22
+ key?: string | number;
23
+ }
24
+ /**
25
+ * Infers component props for JSX tags.
26
+ */
27
+ type LibraryManagedAttributes<ComponentType, Props> = ComponentPropsFor<ComponentType, Props>;
28
+ /**
29
+ * Built-in element props for HTML, SVG, MathML, and custom elements.
30
+ */
31
+ interface IntrinsicElements extends IntrinsicElementsByTagName {
32
+ [elementName: string]: IntrinsicElementProps<any>;
33
+ }
34
+ }
35
+ //#endregion
36
+ export { Fragment, JSX, jsx, jsx as jsxs };
@@ -0,0 +1,2 @@
1
+ import { s as jsx, t as Fragment } from "./vnode-Lr-Tpypk.mjs";
2
+ export { Fragment, jsx, jsx as jsxs };
@@ -0,0 +1,43 @@
1
+ //#region src/macros.d.ts
2
+ /**
3
+ * Marks a component as a browser-hydrated boundary.
4
+ *
5
+ * This function is a compile-time macro. It must be called from a component's
6
+ * `hydrate` option and requires the Pudui Vite plugin to replace it during
7
+ * development and builds.
8
+ *
9
+ * @returns This macro never returns at runtime because it is replaced by the Vite plugin.
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * import { Component } from "pudui";
14
+ * import { hydrate } from "pudui/macros";
15
+ *
16
+ * export function SearchBox() {
17
+ * return new Component({
18
+ * hydrate: hydrate(),
19
+ * render: () => <input type="search" />,
20
+ * });
21
+ * }
22
+ * ```
23
+ */
24
+ declare function hydrate(): never;
25
+ /**
26
+ * Returns the browser entry metadata for the current server module.
27
+ *
28
+ * This function is a compile-time macro. It requires the Pudui Vite plugin and
29
+ * is primarily used by framework integrations that need to emit the browser
30
+ * entry, dependency module URLs, and stylesheet URLs for the current route.
31
+ *
32
+ * @returns A tuple of browser entry URL, dependency URLs, and stylesheet URLs after transformation.
33
+ *
34
+ * @example
35
+ * ```tsx
36
+ * import { entry } from "pudui/macros";
37
+ *
38
+ * const [entryUrl, dependencies, styles] = entry();
39
+ * ```
40
+ */
41
+ declare function entry(): readonly [entry: string, dependencies: string[], styles: string[]];
42
+ //#endregion
43
+ export { entry, hydrate };
@@ -0,0 +1,47 @@
1
+ //#region src/macros.ts
2
+ /**
3
+ * Marks a component as a browser-hydrated boundary.
4
+ *
5
+ * This function is a compile-time macro. It must be called from a component's
6
+ * `hydrate` option and requires the Pudui Vite plugin to replace it during
7
+ * development and builds.
8
+ *
9
+ * @returns This macro never returns at runtime because it is replaced by the Vite plugin.
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * import { Component } from "pudui";
14
+ * import { hydrate } from "pudui/macros";
15
+ *
16
+ * export function SearchBox() {
17
+ * return new Component({
18
+ * hydrate: hydrate(),
19
+ * render: () => <input type="search" />,
20
+ * });
21
+ * }
22
+ * ```
23
+ */
24
+ function hydrate() {
25
+ throw new Error("hydrate() requires vite plugin.");
26
+ }
27
+ /**
28
+ * Returns the browser entry metadata for the current server module.
29
+ *
30
+ * This function is a compile-time macro. It requires the Pudui Vite plugin and
31
+ * is primarily used by framework integrations that need to emit the browser
32
+ * entry, dependency module URLs, and stylesheet URLs for the current route.
33
+ *
34
+ * @returns A tuple of browser entry URL, dependency URLs, and stylesheet URLs after transformation.
35
+ *
36
+ * @example
37
+ * ```tsx
38
+ * import { entry } from "pudui/macros";
39
+ *
40
+ * const [entryUrl, dependencies, styles] = entry();
41
+ * ```
42
+ */
43
+ function entry() {
44
+ throw new Error("entry() requires vite plugin.");
45
+ }
46
+ //#endregion
47
+ export { entry, hydrate };
@@ -0,0 +1,55 @@
1
+ import { A as Fragment, C as RefValue, D as VNode, E as UpdateCallback, F as jsxDEV, M as createElement, N as isVNode, O as Component, P as jsx, S as RefCleanup, T as StyleValue, _ as PreloadResolver, a as ComponentFactoryWithoutProps, b as RawProps, c as ComponentPropsFor, d as EmptyChild, f as IntrinsicElementProps, h as MountCallback, i as ComponentFactoryWithProps, j as Raw, k as isComponent, l as DangerouslySetInnerHTML, m as Key, n as Child, o as ComponentInstance, p as IntrinsicElementsByTagName, r as ComponentFactory, s as ComponentOptions, t as AnyProps, u as ElementType, v as PrimitiveChild, w as RenderableType, x as RefCallback, y as RawChild } from "./core-Cypb6mR9.mjs";
2
+
3
+ //#region src/server.d.ts
4
+ /**
5
+ * Options for rendering Pudui children to an HTML string.
6
+ */
7
+ type RenderToStringOptions = {
8
+ /**
9
+ * Resolves hydration metadata into module and style preload links.
10
+ */
11
+ preload?: PreloadResolver;
12
+ /**
13
+ * Props to apply when rendering an existing component instance.
14
+ */
15
+ props?: AnyProps;
16
+ };
17
+ /**
18
+ * Renders a Pudui child tree to an HTML string.
19
+ *
20
+ * Synchronous components are rendered immediately. Use
21
+ * {@link renderToStringAsync} when component render functions may return async
22
+ * children that need to be awaited by user code before rendering.
23
+ *
24
+ * @param child Child tree or component instance to render.
25
+ * @param propsOrOptions Props for a component instance, or render options.
26
+ * @returns Escaped HTML for the child tree.
27
+ *
28
+ * @example
29
+ * ```tsx
30
+ * import { renderToString } from "pudui/server";
31
+ *
32
+ * const html = renderToString(<main class="page">Hello</main>);
33
+ * ```
34
+ */
35
+ declare function renderToString(child: Child, propsOrOptions?: AnyProps | RenderToStringOptions): string;
36
+ /**
37
+ * Renders a Pudui child tree to an HTML string while awaiting async work.
38
+ *
39
+ * This has the same output shape as {@link renderToString}, but awaits async
40
+ * component rendering paths before returning the final HTML.
41
+ *
42
+ * @param child Child tree or component instance to render.
43
+ * @param propsOrOptions Props for a component instance, or render options.
44
+ * @returns Escaped HTML for the child tree.
45
+ *
46
+ * @example
47
+ * ```tsx
48
+ * import { renderToStringAsync } from "pudui/server";
49
+ *
50
+ * const html = await renderToStringAsync(<Document url={request.url} />);
51
+ * ```
52
+ */
53
+ declare function renderToStringAsync(child: Child, propsOrOptions?: AnyProps | RenderToStringOptions): Promise<string>;
54
+ //#endregion
55
+ export { type AnyProps, type Child, Component, type ComponentFactory, type ComponentFactoryWithProps, type ComponentFactoryWithoutProps, type ComponentInstance, type ComponentOptions, type ComponentPropsFor, type DangerouslySetInnerHTML, type ElementType, type EmptyChild, Fragment, type IntrinsicElementProps, type IntrinsicElementsByTagName, type Key, type MountCallback, type PrimitiveChild, Raw, type RawChild, type RawProps, type RefCallback, type RefCleanup, type RefValue, RenderToStringOptions, type RenderableType, type StyleValue, type UpdateCallback, type VNode, createElement, isComponent, isVNode, jsx, jsx as jsxs, jsxDEV, renderToString, renderToStringAsync };
@@ -0,0 +1,223 @@
1
+ import { a as isHostVNode, c as jsxDEV, d as normalizeChildren, f as readRawChildHtml, i as isComponentVNode, n as Raw, o as isVNode, r as createElement, s as jsx, t as Fragment, u as isRawChild } from "./vnode-Lr-Tpypk.mjs";
2
+ import { _ as serializeAttributeValue, b as validateStyleName, c as serializeHydrateEndComment, d as serializeRawEndComment, f as serializeRawStartComment, g as readDangerouslySetInnerHTML, l as serializeHydrateMetaComment, m as isChildlessElement, p as attributeName, u as serializeHydrateStartComment, v as toKebabCase, x as validateStyleValue, y as validateMarkupName } from "./hydration-markers-DdjOvH6g.mjs";
3
+ import { a as isComponent, c as readComponentProps, d as resolveComponent, f as setComponentProps, i as finishComponentRender, l as renderComponentErrorOutput, n as beginComponentRender, s as readComponentHydrateMeta, t as Component, u as renderComponentOutput } from "./component-D3kwgmef.mjs";
4
+ //#region src/server.ts
5
+ /**
6
+ * Renders a Pudui child tree to an HTML string.
7
+ *
8
+ * Synchronous components are rendered immediately. Use
9
+ * {@link renderToStringAsync} when component render functions may return async
10
+ * children that need to be awaited by user code before rendering.
11
+ *
12
+ * @param child Child tree or component instance to render.
13
+ * @param propsOrOptions Props for a component instance, or render options.
14
+ * @returns Escaped HTML for the child tree.
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * import { renderToString } from "pudui/server";
19
+ *
20
+ * const html = renderToString(<main class="page">Hello</main>);
21
+ * ```
22
+ */
23
+ function renderToString(child, propsOrOptions) {
24
+ const options = renderToStringOptions(child, propsOrOptions);
25
+ const props = options === propsOrOptions ? options.props : propsOrOptions;
26
+ if (isComponent(child) && props !== void 0) setComponentProps(child, props);
27
+ return childToString(child, void 0, createRenderToStringContext(options));
28
+ }
29
+ /**
30
+ * Renders a Pudui child tree to an HTML string while awaiting async work.
31
+ *
32
+ * This has the same output shape as {@link renderToString}, but awaits async
33
+ * component rendering paths before returning the final HTML.
34
+ *
35
+ * @param child Child tree or component instance to render.
36
+ * @param propsOrOptions Props for a component instance, or render options.
37
+ * @returns Escaped HTML for the child tree.
38
+ *
39
+ * @example
40
+ * ```tsx
41
+ * import { renderToStringAsync } from "pudui/server";
42
+ *
43
+ * const html = await renderToStringAsync(<Document url={request.url} />);
44
+ * ```
45
+ */
46
+ async function renderToStringAsync(child, propsOrOptions) {
47
+ const options = renderToStringOptions(child, propsOrOptions);
48
+ const props = options === propsOrOptions ? options.props : propsOrOptions;
49
+ if (isComponent(child) && props !== void 0) setComponentProps(child, props);
50
+ return childToStringAsync(child, void 0, createRenderToStringContext(options));
51
+ }
52
+ function renderToStringOptions(child, propsOrOptions) {
53
+ if (propsOrOptions !== void 0 && (!isComponent(child) || "props" in propsOrOptions) && ("preload" in propsOrOptions || "props" in propsOrOptions)) return propsOrOptions;
54
+ return {};
55
+ }
56
+ function createRenderToStringContext(options) {
57
+ return {
58
+ emittedHydrateMetaIds: /* @__PURE__ */ new Set(),
59
+ emittedModulePreloads: /* @__PURE__ */ new Set(),
60
+ emittedStylePreloads: /* @__PURE__ */ new Set(),
61
+ hydrateMetaIds: /* @__PURE__ */ new Map(),
62
+ nextHydrateId: 1,
63
+ preload: options.preload
64
+ };
65
+ }
66
+ function childToString(child, owner, context, key) {
67
+ if (child === false || child === true || child === null || child === void 0) return "";
68
+ if (typeof child === "string" || typeof child === "number" || typeof child === "bigint") return escapeText(String(child));
69
+ if (isRawChild(child)) return rawToString(child);
70
+ if (Array.isArray(child)) return normalizeChildren(child).map((nestedChild) => childToString(nestedChild, owner, context)).join("");
71
+ if (isComponent(child)) {
72
+ beginComponentRender(child);
73
+ try {
74
+ let renderedChild;
75
+ try {
76
+ renderedChild = childToString(renderComponentOutput(child), child, context);
77
+ } catch (reason) {
78
+ beginComponentRender(child);
79
+ renderedChild = childToString(renderComponentErrorOutput(child, reason), child, context);
80
+ }
81
+ return wrapHydratedComponent(child, renderedChild, context, key);
82
+ } finally {
83
+ finishComponentRender(child);
84
+ }
85
+ }
86
+ if (isVNode(child)) {
87
+ if (isComponentVNode(child)) return childToString(resolveComponent(child, owner), owner, context, child.key);
88
+ if (isHostVNode(child)) return elementToString(child, owner, context);
89
+ }
90
+ return "";
91
+ }
92
+ async function childToStringAsync(child, owner, context, key) {
93
+ if (child === false || child === true || child === null || child === void 0) return "";
94
+ if (typeof child === "string" || typeof child === "number" || typeof child === "bigint") return escapeText(String(child));
95
+ if (isRawChild(child)) return rawToString(child);
96
+ if (Array.isArray(child)) {
97
+ const renderedChildren = [];
98
+ for (const nestedChild of normalizeChildren(child)) renderedChildren.push(await childToStringAsync(nestedChild, owner, context));
99
+ return renderedChildren.join("");
100
+ }
101
+ if (isComponent(child)) {
102
+ beginComponentRender(child);
103
+ try {
104
+ let renderedChild;
105
+ try {
106
+ renderedChild = await childToStringAsync(renderComponentOutput(child), child, context);
107
+ } catch (reason) {
108
+ beginComponentRender(child);
109
+ renderedChild = await childToStringAsync(renderComponentErrorOutput(child, reason), child, context);
110
+ }
111
+ return wrapHydratedComponent(child, renderedChild, context, key);
112
+ } finally {
113
+ finishComponentRender(child);
114
+ }
115
+ }
116
+ if (isVNode(child)) {
117
+ if (isComponentVNode(child)) return childToStringAsync(resolveComponent(child, owner), owner, context, child.key);
118
+ if (isHostVNode(child)) return elementToStringAsync(child, owner, context);
119
+ }
120
+ return "";
121
+ }
122
+ function rawToString(raw) {
123
+ return `${serializeRawStartComment()}${readRawChildHtml(raw)}${serializeRawEndComment()}`;
124
+ }
125
+ function wrapHydratedComponent(component, renderedChild, context, key) {
126
+ const hydrateMeta = readComponentHydrateMeta(component);
127
+ if (hydrateMeta === void 0) return renderedChild;
128
+ const hydrateMetaJson = serializeHydrateJson(hydrateMeta);
129
+ let id = context.hydrateMetaIds.get(hydrateMetaJson);
130
+ if (id === void 0) {
131
+ id = context.nextHydrateId++;
132
+ context.hydrateMetaIds.set(hydrateMetaJson, id);
133
+ }
134
+ let output = "";
135
+ output += preloadsToString(hydrateMeta, context);
136
+ if (!context.emittedHydrateMetaIds.has(id)) {
137
+ context.emittedHydrateMetaIds.add(id);
138
+ output += serializeHydrateMetaComment(id, hydrateMetaJson);
139
+ }
140
+ const props = readComponentProps(component);
141
+ const propsJson = serializeHydrateJson(key === void 0 ? props : [props, key], { skipChildren: true });
142
+ return `${output}${serializeHydrateStartComment(id, propsJson)}${renderedChild}${serializeHydrateEndComment()}`;
143
+ }
144
+ function preloadsToString(meta, context) {
145
+ const preload = context.preload?.(meta);
146
+ if (preload === void 0 || preload === null) return "";
147
+ let output = "";
148
+ for (const href of preload.modulePreloads ?? []) {
149
+ if (context.emittedModulePreloads.has(href)) continue;
150
+ context.emittedModulePreloads.add(href);
151
+ output += `<link rel="modulepreload" href="${escapeAttribute(href)}">`;
152
+ }
153
+ for (const href of preload.stylePreloads ?? []) {
154
+ if (context.emittedStylePreloads.has(href)) continue;
155
+ context.emittedStylePreloads.add(href);
156
+ output += `<link rel="stylesheet" href="${escapeAttribute(href)}">`;
157
+ }
158
+ return output;
159
+ }
160
+ function elementToString(vnode, owner, context) {
161
+ const tagName = vnode.type;
162
+ const attributes = propsToAttributes(vnode.props);
163
+ if (isChildlessElement(tagName)) return `<${tagName}${attributes}>`;
164
+ return `<${tagName}${attributes}>${readDangerouslySetInnerHTML(vnode.props) ?? childToString(vnode.props.children, owner, context)}</${tagName}>`;
165
+ }
166
+ async function elementToStringAsync(vnode, owner, context) {
167
+ const tagName = vnode.type;
168
+ const attributes = propsToAttributes(vnode.props);
169
+ if (isChildlessElement(tagName)) return `<${tagName}${attributes}>`;
170
+ return `<${tagName}${attributes}>${readDangerouslySetInnerHTML(vnode.props) ?? await childToStringAsync(vnode.props.children, owner, context)}</${tagName}>`;
171
+ }
172
+ function serializeHydrateJson(value, options) {
173
+ const json = JSON.stringify(value, (key, nestedValue) => {
174
+ if (options?.skipChildren && key === "children" || key === "key" || key === "ref" || key.startsWith("on") || typeof nestedValue === "function" || typeof nestedValue === "symbol" || typeof nestedValue === "undefined") return;
175
+ if (typeof nestedValue === "bigint") return String(nestedValue);
176
+ return nestedValue;
177
+ });
178
+ if (json === void 0) throw new TypeError("Hydration values must be JSON serializable.");
179
+ return json;
180
+ }
181
+ function propsToAttributes(props) {
182
+ let attributes = "";
183
+ for (const [rawName, value] of Object.entries(props)) {
184
+ if (shouldSkipAttribute(rawName, value)) continue;
185
+ const name = attributeName(rawName);
186
+ validateMarkupName(name, "attribute");
187
+ if (name === "style") {
188
+ const serializedStyle = serializeStyle(value);
189
+ if (serializedStyle) attributes += ` style="${escapeAttribute(serializedStyle)}"`;
190
+ continue;
191
+ }
192
+ if (value === true) attributes += ` ${name}`;
193
+ else {
194
+ const attributeValue = serializeAttributeValue(value);
195
+ if (attributeValue !== void 0) attributes += ` ${name}="${escapeAttribute(attributeValue)}"`;
196
+ }
197
+ }
198
+ return attributes;
199
+ }
200
+ function shouldSkipAttribute(name, value) {
201
+ return name === "children" || name === "dangerouslySetInnerHTML" || name === "key" || name === "ref" || name.startsWith("on") || value === false || value === null || value === void 0;
202
+ }
203
+ function serializeStyle(style) {
204
+ if (!isStyleObject(style)) throw new TypeError("Style prop must be an object.");
205
+ return Object.entries(style).filter((entry) => entry[1] !== null && entry[1] !== void 0 && entry[1] !== "").map(([name, value]) => {
206
+ const propertyName = toKebabCase(name);
207
+ const propertyValue = String(value);
208
+ validateStyleName(propertyName);
209
+ validateStyleValue(propertyValue);
210
+ return `${propertyName}: ${propertyValue}`;
211
+ }).join("; ");
212
+ }
213
+ function isStyleObject(value) {
214
+ return typeof value === "object" && value !== null && !Array.isArray(value);
215
+ }
216
+ function escapeText(value) {
217
+ return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
218
+ }
219
+ function escapeAttribute(value) {
220
+ return escapeText(value).replaceAll("\"", "&quot;");
221
+ }
222
+ //#endregion
223
+ export { Component, Fragment, Raw, createElement, isComponent, isVNode, jsx, jsx as jsxs, jsxDEV, renderToString, renderToStringAsync };