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,218 @@
1
+ //#region src/core/attributes.ts
2
+ const childlessElementNames = " area base br col embed hr img input link meta param source track wbr ";
3
+ /**
4
+ * Checks whether an HTML element must not render child content.
5
+ *
6
+ * @param name Element tag name.
7
+ * @returns `true` for void HTML elements such as `br`, `img`, and `input`.
8
+ */
9
+ function isChildlessElement(name) {
10
+ return childlessElementNames.includes(" " + name + " ");
11
+ }
12
+ /**
13
+ * Reads trusted inner HTML from intrinsic element props.
14
+ *
15
+ * @param props Element props to inspect.
16
+ * @returns Trusted HTML string, or `undefined` when none was provided.
17
+ */
18
+ function readDangerouslySetInnerHTML(props) {
19
+ return props.dangerouslySetInnerHTML?.__html;
20
+ }
21
+ /**
22
+ * Converts JSX prop names to DOM attribute names.
23
+ *
24
+ * @param name JSX prop name.
25
+ * @returns Serialized attribute name.
26
+ */
27
+ function attributeName(name) {
28
+ return name === "className" ? "class" : name === "htmlFor" ? "for" : name;
29
+ }
30
+ /**
31
+ * Validates a CSS property name before serialization.
32
+ *
33
+ * @param name CSS property name.
34
+ */
35
+ function validateStyleName(name) {
36
+ if (name === "" || hasAsciiControl(name) || /[\s:;{}]/u.test(name)) throw new TypeError(`Bad CSS name: ${name}`);
37
+ }
38
+ /**
39
+ * Validates a CSS property value before serialization.
40
+ *
41
+ * @param value CSS property value.
42
+ */
43
+ function validateStyleValue(value) {
44
+ if (hasAsciiControl(value) || /[;{}]/u.test(value)) throw new TypeError("Bad CSS value.");
45
+ }
46
+ /**
47
+ * Converts primitive prop values to attribute strings.
48
+ *
49
+ * @param value Value to serialize.
50
+ * @returns Attribute text for primitive values, otherwise `undefined`.
51
+ */
52
+ function serializeAttributeValue(value) {
53
+ if (isPrimitiveValue(value)) return String(value);
54
+ }
55
+ /**
56
+ * Checks whether a value renders as primitive text.
57
+ *
58
+ * @param value Value to inspect.
59
+ * @returns `true` for strings, numbers, and bigints.
60
+ */
61
+ function isPrimitiveValue(value) {
62
+ const valueType = typeof value;
63
+ return valueType === "string" || valueType === "number" || valueType === "bigint";
64
+ }
65
+ /**
66
+ * Converts camel-case CSS names to kebab-case.
67
+ *
68
+ * @param value Name to convert.
69
+ * @returns Kebab-case name.
70
+ */
71
+ function toKebabCase(value) {
72
+ return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
73
+ }
74
+ /**
75
+ * Validates an element or attribute name before serialization.
76
+ *
77
+ * @param name Markup name to validate.
78
+ * @param kind Name kind used in error messages.
79
+ */
80
+ function validateMarkupName(name, kind) {
81
+ if (name === "" || hasAsciiControl(name) || /[\s"'<>/=]/u.test(name)) throw new TypeError(`Bad ${kind}: ${name}`);
82
+ }
83
+ function hasAsciiControl(value) {
84
+ for (let index = 0; index < value.length; index++) {
85
+ const code = value.charCodeAt(index);
86
+ if (code <= 31 || code === 127) return true;
87
+ }
88
+ return false;
89
+ }
90
+ //#endregion
91
+ //#region src/hydration-markers.ts
92
+ /**
93
+ * Serializes hydration metadata into an HTML comment.
94
+ *
95
+ * @param index Boundary metadata index.
96
+ * @param json JSON metadata payload.
97
+ * @returns HTML comment string.
98
+ */
99
+ function serializeHydrateMetaComment(index, json) {
100
+ return `<!--m:${index}:${escapeCommentJson(json)}-->`;
101
+ }
102
+ /**
103
+ * Serializes a hydration boundary start marker.
104
+ *
105
+ * @param index Boundary metadata index.
106
+ * @param json JSON props payload.
107
+ * @returns HTML comment string.
108
+ */
109
+ function serializeHydrateStartComment(index, json) {
110
+ return `<!--h:${index}:${escapeCommentJson(json)}-->`;
111
+ }
112
+ /**
113
+ * Serializes a hydration boundary end marker.
114
+ *
115
+ * @returns HTML comment string.
116
+ */
117
+ function serializeHydrateEndComment() {
118
+ return "<!--/h-->";
119
+ }
120
+ /**
121
+ * Serializes a raw HTML boundary start marker.
122
+ *
123
+ * @returns HTML comment string.
124
+ */
125
+ function serializeRawStartComment() {
126
+ return "<!--r-->";
127
+ }
128
+ /**
129
+ * Serializes a raw HTML boundary end marker.
130
+ *
131
+ * @returns HTML comment string.
132
+ */
133
+ function serializeRawEndComment() {
134
+ return "<!--/r-->";
135
+ }
136
+ /**
137
+ * Checks whether comment data is a hydration metadata marker.
138
+ *
139
+ * @param data Comment data.
140
+ * @returns `true` for hydration metadata markers.
141
+ */
142
+ function isHydrateMetaCommentData(data) {
143
+ return data.startsWith("m:");
144
+ }
145
+ /**
146
+ * Checks whether comment data starts a hydration boundary.
147
+ *
148
+ * @param data Comment data.
149
+ * @returns `true` for hydration start markers.
150
+ */
151
+ function isHydrateStartCommentData(data) {
152
+ return data.startsWith("h:");
153
+ }
154
+ /**
155
+ * Checks whether comment data ends a hydration boundary.
156
+ *
157
+ * @param data Comment data.
158
+ * @returns `true` for hydration end markers.
159
+ */
160
+ function isHydrateEndCommentData(data) {
161
+ return data === "/h";
162
+ }
163
+ /**
164
+ * Checks whether comment data starts a raw HTML boundary.
165
+ *
166
+ * @param data Comment data.
167
+ * @returns `true` for raw start markers.
168
+ */
169
+ function isRawStartCommentData(data) {
170
+ return data === "r";
171
+ }
172
+ /**
173
+ * Checks whether comment data ends a raw HTML boundary.
174
+ *
175
+ * @param data Comment data.
176
+ * @returns `true` for raw end markers.
177
+ */
178
+ function isRawEndCommentData(data) {
179
+ return data === "/r";
180
+ }
181
+ /**
182
+ * Parses hydration metadata comment data.
183
+ *
184
+ * @param data Comment data without `<!--` and `-->`.
185
+ * @returns Parsed metadata, or `undefined` when the data is not a metadata marker.
186
+ */
187
+ function parseHydrateMetaCommentData(data) {
188
+ return parseMarker(data, "m:", "v");
189
+ }
190
+ /**
191
+ * Parses hydration boundary start comment data.
192
+ *
193
+ * @param data Comment data without `<!--` and `-->`.
194
+ * @returns Parsed boundary start metadata, or `undefined` when the data is not a start marker.
195
+ */
196
+ function parseHydrateStartCommentData(data) {
197
+ return parseMarker(data, "h:", "p");
198
+ }
199
+ function parseMarker(data, prefix, key) {
200
+ if (!data.startsWith(prefix)) return;
201
+ const split = data.indexOf(":", prefix.length);
202
+ if (split < 0) return;
203
+ const value = JSON.parse(data.slice(split + 1));
204
+ if (key === "p" && Array.isArray(value) && value.length === 2 && (value[1] === null || typeof value[1] === "string" || typeof value[1] === "number")) return {
205
+ i: +data.slice(prefix.length, split),
206
+ k: value[1] ?? void 0,
207
+ p: value[0]
208
+ };
209
+ return {
210
+ i: +data.slice(prefix.length, split),
211
+ [key]: value
212
+ };
213
+ }
214
+ function escapeCommentJson(value) {
215
+ return value.replaceAll("<", "\\u003c").replaceAll("--", "\\u002d\\u002d");
216
+ }
217
+ //#endregion
218
+ export { serializeAttributeValue as _, isRawStartCommentData as a, validateStyleName as b, serializeHydrateEndComment as c, serializeRawEndComment as d, serializeRawStartComment as f, readDangerouslySetInnerHTML as g, isPrimitiveValue as h, isRawEndCommentData as i, serializeHydrateMetaComment as l, isChildlessElement as m, isHydrateMetaCommentData as n, parseHydrateMetaCommentData as o, attributeName as p, isHydrateStartCommentData as r, parseHydrateStartCommentData as s, isHydrateEndCommentData as t, serializeHydrateStartComment as u, toKebabCase as v, validateStyleValue as x, validateMarkupName as y };
@@ -0,0 +1,109 @@
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, g as PreloadMetadata, 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/client.d.ts
4
+ /**
5
+ * Event listener callback type used by browser integrations.
6
+ */
7
+ type EventHandler<EventType extends Event = Event> = (event: EventType) => void;
8
+ /**
9
+ * Resolves the DOM event type associated with an event name.
10
+ *
11
+ * Known HTML, SVG, MathML, document, and window event names resolve to their
12
+ * matching event object type. Unknown names fall back to `Event`.
13
+ */
14
+ type EventForName<Name extends string> = Name extends keyof HTMLElementEventMap ? HTMLElementEventMap[Name] : Name extends keyof SVGElementEventMap ? SVGElementEventMap[Name] : Name extends keyof MathMLElementEventMap ? MathMLElementEventMap[Name] : Name extends keyof DocumentEventMap ? DocumentEventMap[Name] : Name extends keyof WindowEventMap ? WindowEventMap[Name] : Event;
15
+ /**
16
+ * Loads a component factory for a server-rendered hydration boundary.
17
+ *
18
+ * The `meta` value is generated by the `hydrate()` macro transform and is
19
+ * usually consumed by `pudui/vite-runtime`.
20
+ */
21
+ type HydrateLoad = (meta: unknown) => ComponentFactory | Promise<ComponentFactory>;
22
+ /**
23
+ * Options for hydrating server-rendered Pudui markup in the browser.
24
+ */
25
+ type HydrateOptions = {
26
+ /**
27
+ * Resolves the component factory for a hydration boundary.
28
+ */
29
+ load: HydrateLoad;
30
+ };
31
+ /**
32
+ * A mounted browser root returned by {@link render} or {@link hydrate}.
33
+ */
34
+ type HydrationRoot = {
35
+ /**
36
+ * Replaces the root child and patches the DOM.
37
+ *
38
+ * @param child Next child tree to render.
39
+ */
40
+ rerender(child: Child): void;
41
+ /**
42
+ * Removes rendered content and releases component subscriptions and refs.
43
+ */
44
+ unmount(): void;
45
+ };
46
+ /**
47
+ * Creates a ref that wires a DOM event listener to an element.
48
+ *
49
+ * Each time the event fires, the previous handler invocation for that element
50
+ * is aborted and the new invocation receives a fresh `AbortSignal`. This makes
51
+ * async event handlers straightforward to cancel during rapid input.
52
+ *
53
+ * @param type DOM event name to listen for.
54
+ * @param handler Callback invoked for each event with a cancellation signal.
55
+ * @param options Options passed to `addEventListener`.
56
+ * @returns A ref callback that installs and removes the listener.
57
+ *
58
+ * @example
59
+ * ```tsx
60
+ * <button
61
+ * ref={event("click", async (_event, signal) => {
62
+ * await save({ signal });
63
+ * })}
64
+ * >
65
+ * Save
66
+ * </button>
67
+ * ```
68
+ */
69
+ declare function event<Name extends string>(type: Name, handler: (event: EventForName<Name>, signal: AbortSignal) => void, options?: boolean | AddEventListenerOptions): RefCallback;
70
+ /**
71
+ * Mounts a child tree into a DOM container.
72
+ *
73
+ * The container's existing children are replaced on the initial render. Later
74
+ * calls to `rerender()` patch the DOM in place when possible.
75
+ *
76
+ * @param child Child tree to render.
77
+ * @param container DOM element or fragment to own.
78
+ * @returns A root controller for rerendering or unmounting.
79
+ *
80
+ * @example
81
+ * ```tsx
82
+ * import { render } from "pudui";
83
+ *
84
+ * const root = render(<main>Hello</main>, document.body);
85
+ * root.rerender(<main>Updated</main>);
86
+ * ```
87
+ */
88
+ declare function render(child: Child, container: Element | DocumentFragment): HydrationRoot;
89
+ /**
90
+ * Hydrates server-rendered Pudui boundaries in a document or element.
91
+ *
92
+ * The root scans for hydration comments emitted by `renderToString()` and uses
93
+ * `options.load` to import component factories when a boundary becomes active.
94
+ *
95
+ * @param root Document, element, or fragment containing server-rendered markup.
96
+ * @param options Hydration loader options.
97
+ * @returns A root controller for rerendering or unmounting.
98
+ *
99
+ * @example
100
+ * ```tsx
101
+ * import { hydrate } from "pudui";
102
+ * import { load } from "pudui/vite-runtime";
103
+ *
104
+ * hydrate(document, { load });
105
+ * ```
106
+ */
107
+ declare function hydrate(root: Document | DocumentFragment | Element, options: HydrateOptions): HydrationRoot;
108
+ //#endregion
109
+ export { type AnyProps, type Child, Component, type ComponentFactory, type ComponentFactoryWithProps, type ComponentFactoryWithoutProps, type ComponentInstance, type ComponentOptions, type ComponentPropsFor, type DangerouslySetInnerHTML, type ElementType, type EmptyChild, type EventForName, type EventHandler, Fragment, type HydrateLoad, type HydrateOptions, type HydrationRoot, type IntrinsicElementProps, type IntrinsicElementsByTagName, type Key, type MountCallback, type PreloadMetadata, type PreloadResolver, type PrimitiveChild, Raw, type RawChild, type RawProps, type RefCallback, type RefCleanup, type RefValue, type RenderableType, type StyleValue, type UpdateCallback, type VNode, createElement, event, hydrate, isComponent, isVNode, jsx, jsx as jsxs, jsxDEV, render };