sibujs 1.2.0 → 1.4.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.
Files changed (95) hide show
  1. package/README.md +29 -25
  2. package/dist/browser.cjs +804 -2
  3. package/dist/browser.d.cts +591 -1
  4. package/dist/browser.d.ts +591 -1
  5. package/dist/browser.js +50 -8
  6. package/dist/build.cjs +655 -237
  7. package/dist/build.js +15 -93
  8. package/dist/cdn.global.js +188 -7
  9. package/dist/chunk-2BYQDGN3.js +742 -0
  10. package/dist/chunk-32DY64NT.js +282 -0
  11. package/dist/chunk-3AIRKM3B.js +1263 -0
  12. package/dist/chunk-3X2YG6YM.js +505 -0
  13. package/dist/chunk-5X6PP2UK.js +28 -0
  14. package/dist/chunk-77L6NL3X.js +1097 -0
  15. package/dist/chunk-BGN5ZMP4.js +26 -0
  16. package/dist/chunk-BTU3TJDS.js +365 -0
  17. package/dist/chunk-CHF5OHIA.js +61 -0
  18. package/dist/chunk-CMBFNA7L.js +27 -0
  19. package/dist/chunk-CNZ35WI2.js +178 -0
  20. package/dist/chunk-DAHRH4ON.js +331 -0
  21. package/dist/chunk-EBGIRKQY.js +616 -0
  22. package/dist/chunk-EUZND3CB.js +27 -0
  23. package/dist/chunk-F3FA4F32.js +292 -0
  24. package/dist/chunk-JAKHTMQU.js +1000 -0
  25. package/dist/chunk-JCI5M6U6.js +956 -0
  26. package/dist/chunk-KQPDEVVS.js +398 -0
  27. package/dist/chunk-M4NLBH4I.js +725 -0
  28. package/dist/chunk-NEKUBFPT.js +60 -0
  29. package/dist/chunk-NYVAC6P5.js +37 -0
  30. package/dist/chunk-PTQJDMRT.js +146 -0
  31. package/dist/chunk-QWZG56ET.js +2744 -0
  32. package/dist/chunk-TSOKIX5Z.js +654 -0
  33. package/dist/chunk-UHNL42EF.js +2730 -0
  34. package/dist/chunk-VRW3FULF.js +725 -0
  35. package/dist/chunk-WZSPOOER.js +84 -0
  36. package/dist/chunk-YT6HQ6AM.js +14 -0
  37. package/dist/chunk-ZD6OAMTH.js +277 -0
  38. package/dist/chunk-ZWKZCBO6.js +317 -0
  39. package/dist/contracts-DDrwxvJ-.d.cts +245 -0
  40. package/dist/contracts-DDrwxvJ-.d.ts +245 -0
  41. package/dist/contracts-xo5ckdRP.d.cts +240 -0
  42. package/dist/contracts-xo5ckdRP.d.ts +240 -0
  43. package/dist/data.cjs +35 -2
  44. package/dist/data.d.cts +7 -0
  45. package/dist/data.d.ts +7 -0
  46. package/dist/data.js +9 -8
  47. package/dist/devtools.cjs +122 -0
  48. package/dist/devtools.d.cts +69 -461
  49. package/dist/devtools.d.ts +69 -461
  50. package/dist/devtools.js +127 -6
  51. package/dist/ecosystem.cjs +23 -6
  52. package/dist/ecosystem.d.cts +1 -1
  53. package/dist/ecosystem.d.ts +1 -1
  54. package/dist/ecosystem.js +10 -9
  55. package/dist/extras.cjs +1208 -88
  56. package/dist/extras.d.cts +6 -6
  57. package/dist/extras.d.ts +6 -6
  58. package/dist/extras.js +70 -33
  59. package/dist/index.cjs +663 -158
  60. package/dist/index.d.cts +398 -40
  61. package/dist/index.d.ts +398 -40
  62. package/dist/index.js +39 -21
  63. package/dist/introspect-BumjnBKr.d.cts +477 -0
  64. package/dist/introspect-CZrlcaYy.d.ts +477 -0
  65. package/dist/introspect-Cb0zgpi2.d.cts +477 -0
  66. package/dist/introspect-Y2xNXGSf.d.ts +477 -0
  67. package/dist/motion.js +4 -4
  68. package/dist/patterns.cjs +51 -24
  69. package/dist/patterns.d.cts +19 -57
  70. package/dist/patterns.d.ts +19 -57
  71. package/dist/patterns.js +8 -16
  72. package/dist/performance.js +4 -4
  73. package/dist/plugins.cjs +429 -82
  74. package/dist/plugins.d.cts +27 -4
  75. package/dist/plugins.d.ts +27 -4
  76. package/dist/plugins.js +156 -37
  77. package/dist/ssr-4PBXAOO3.js +40 -0
  78. package/dist/ssr-Do_SiVoL.d.cts +201 -0
  79. package/dist/ssr-Do_SiVoL.d.ts +201 -0
  80. package/dist/ssr.cjs +312 -60
  81. package/dist/ssr.d.cts +10 -1
  82. package/dist/ssr.d.ts +10 -1
  83. package/dist/ssr.js +13 -10
  84. package/dist/tagFactory-DaJ0YWX6.d.cts +47 -0
  85. package/dist/tagFactory-DaJ0YWX6.d.ts +47 -0
  86. package/dist/testing.cjs +233 -2
  87. package/dist/testing.d.cts +42 -1
  88. package/dist/testing.d.ts +42 -1
  89. package/dist/testing.js +129 -2
  90. package/dist/ui.cjs +374 -8
  91. package/dist/ui.d.cts +252 -2
  92. package/dist/ui.d.ts +252 -2
  93. package/dist/ui.js +329 -11
  94. package/dist/widgets.js +7 -7
  95. package/package.json +1 -1
@@ -0,0 +1,240 @@
1
+ /**
2
+ * Higher-order component utilities for SibuJS.
3
+ * These functions wrap or compose components to add behavior.
4
+ */
5
+ type Component<P = unknown> = (props: P) => HTMLElement;
6
+ /**
7
+ * Wraps a component with additional behavior that runs before/after rendering.
8
+ *
9
+ * @param WrappedComponent The component to wrap
10
+ * @param wrapper Function that receives the component and its props, returns enhanced element
11
+ * @returns A new component function
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const WithLogging = withWrapper(MyComponent, (Comp, props) => {
16
+ * console.log("Rendering with props:", props);
17
+ * return Comp(props);
18
+ * });
19
+ * ```
20
+ */
21
+ declare function withWrapper<P>(WrappedComponent: Component<P>, wrapper: (component: Component<P>, props: P) => HTMLElement): Component<P>;
22
+ /**
23
+ * Adds default props to a component. Missing props are filled from defaults.
24
+ *
25
+ * @param component The component to wrap
26
+ * @param defaults Default prop values
27
+ * @returns A new component with defaults applied
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const Button = withDefaults(RawButton, { type: "button", disabled: false });
32
+ * Button({ nodes: "Click" }); // type="button", disabled=false automatically
33
+ * ```
34
+ */
35
+ declare function withDefaults<P extends Record<string, unknown>>(component: Component<P>, defaults: Partial<P>): Component<Partial<P>>;
36
+ /**
37
+ * Composes multiple HOC wrappers into a single wrapper.
38
+ * Applied from right to left (like function composition).
39
+ *
40
+ * @param wrappers Array of HOC functions
41
+ * @returns A function that applies all wrappers to a component
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * const enhance = compose(withAuth, withLogging, withTheme);
46
+ * const EnhancedPage = enhance(Page);
47
+ * ```
48
+ */
49
+ declare function compose(...wrappers: Array<(component: Component) => Component>): (component: Component) => Component;
50
+
51
+ /**
52
+ * RenderProp implements the render-prop pattern.
53
+ * The render function receives data and returns DOM nodes.
54
+ */
55
+ declare function RenderProp<T>(props: {
56
+ data: () => T;
57
+ render: (data: T) => HTMLElement;
58
+ }): HTMLElement;
59
+ /**
60
+ * withBoundary creates an isolated component boundary for debugging.
61
+ * Wraps component output in a named container with error isolation.
62
+ */
63
+ declare function withBoundary(name: string, component: (props?: unknown) => HTMLElement): (props?: unknown) => HTMLElement;
64
+ /**
65
+ * Slot pattern — provides named slots for component composition.
66
+ */
67
+ declare function createSlots(slots: Record<string, () => HTMLElement | HTMLElement[] | null>): {
68
+ renderSlot: (name: string, fallback?: () => HTMLElement) => HTMLElement | null;
69
+ hasSlot: (name: string) => boolean;
70
+ };
71
+
72
+ /**
73
+ * Functional component props with TypeScript inference for SibuJS.
74
+ *
75
+ * Provides utilities to define typed components with prop defaults,
76
+ * nodes slots, and prop mapping — all with full TypeScript inference.
77
+ */
78
+ /**
79
+ * Extract the props type from a component defined with defineComponent.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * const Button = defineComponent<{ label: string }>({
84
+ * setup(props) { ... }
85
+ * });
86
+ * type ButtonProps = ComponentProps<typeof Button>; // { label: string }
87
+ * ```
88
+ */
89
+ type ComponentProps<T> = T extends (props: infer P) => HTMLElement ? P : never;
90
+ /**
91
+ * Props that include an optional nodes slot.
92
+ */
93
+ type WithNodes<Props> = Props & {
94
+ nodes?: Node | Node[];
95
+ };
96
+ /**
97
+ * Define a typed component with props inference, defaults, and a setup function.
98
+ *
99
+ * The `setup` function receives merged props (defaults + provided) and must
100
+ * return an HTMLElement. TypeScript infers the full props type from the generic.
101
+ *
102
+ * @param config Component configuration with optional defaults and a setup function
103
+ * @returns A component function that accepts props and returns an HTMLElement
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * const Button = defineComponent<{ label: string; variant?: 'primary' | 'secondary'; disabled?: boolean }>({
108
+ * defaults: { variant: 'primary', disabled: false },
109
+ * setup(props) {
110
+ * return button({
111
+ * class: `btn btn-${props.variant}`,
112
+ * disabled: props.disabled,
113
+ * nodes: props.label
114
+ * });
115
+ * }
116
+ * });
117
+ *
118
+ * // Usage: Button({ label: 'Click me' }) — TypeScript infers props
119
+ * ```
120
+ */
121
+ declare function defineComponent<Props extends Record<string, unknown>>(config: {
122
+ defaults?: Partial<Props>;
123
+ setup: (props: Props) => HTMLElement;
124
+ }): (props: Props) => HTMLElement;
125
+ /**
126
+ * Create a component with nodes slot support.
127
+ *
128
+ * Nodes are passed as a special `nodes` prop alongside the component's
129
+ * own props. This enables composition patterns where a parent component
130
+ * wraps arbitrary child content.
131
+ *
132
+ * @param config Component configuration with optional defaults and a setup function
133
+ * @returns A component function that accepts props (including nodes) and returns an HTMLElement
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * const Card = defineSlottedComponent<{ title: string }>({
138
+ * setup(props) {
139
+ * const el = div({ class: 'card' });
140
+ * el.appendChild(h2({ nodes: props.title }));
141
+ * if (props.nodes) {
142
+ * const nodes = Array.isArray(props.nodes) ? props.nodes : [props.nodes];
143
+ * nodes.forEach(child => el.appendChild(child));
144
+ * }
145
+ * return el;
146
+ * }
147
+ * });
148
+ *
149
+ * // Usage: Card({ title: 'Hello', nodes: p({ nodes: 'World' }) })
150
+ * ```
151
+ */
152
+ declare function defineSlottedComponent<Props extends Record<string, unknown>>(config: {
153
+ defaults?: Partial<Props>;
154
+ setup: (props: WithNodes<Props>) => HTMLElement;
155
+ }): (props: WithNodes<Props>) => HTMLElement;
156
+ /**
157
+ * Higher-order helper to create a component that maps outer props to inner props.
158
+ *
159
+ * Useful for adapting a generic component to a specific use case by transforming
160
+ * the prop interface without modifying the original component.
161
+ *
162
+ * @param component The inner component to forward mapped props to
163
+ * @param mapProps A function that transforms outer props into inner props
164
+ * @returns A new component that accepts outer props
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * const IconButton = defineComponent<{ icon: string; label: string; size: number }>({
169
+ * setup(props) { ... }
170
+ * });
171
+ *
172
+ * const SmallIconButton = withProps(IconButton, (outer: { icon: string; label: string }) => ({
173
+ * icon: outer.icon,
174
+ * label: outer.label,
175
+ * size: 16
176
+ * }));
177
+ *
178
+ * // Usage: SmallIconButton({ icon: 'star', label: 'Favorite' })
179
+ * ```
180
+ */
181
+ declare function withProps<OuterProps extends Record<string, unknown>, InnerProps extends Record<string, unknown>>(component: (props: InnerProps) => HTMLElement, mapProps: (outer: OuterProps) => InnerProps): (props: OuterProps) => HTMLElement;
182
+
183
+ /**
184
+ * Runtime prop validation and strict typing contracts for SibuJS.
185
+ * Provides runtime type checking for component props in development mode.
186
+ */
187
+ /** Validator function: returns true if valid, or an error message string. */
188
+ type Validator<T = unknown> = (value: T, propName: string) => true | string;
189
+ /** Built-in validators */
190
+ declare const validators: {
191
+ string: Validator;
192
+ number: Validator;
193
+ boolean: Validator;
194
+ function: Validator;
195
+ object: Validator;
196
+ array: Validator;
197
+ required: Validator;
198
+ oneOf: <T>(...values: T[]) => Validator<T>;
199
+ instanceOf: <T>(ctor: new (...args: unknown[]) => T) => Validator<T>;
200
+ arrayOf: (itemValidator: Validator) => Validator<unknown[]>;
201
+ shape: (schema: Record<string, Validator>) => Validator<Record<string, unknown>>;
202
+ optional: (validator: Validator) => Validator;
203
+ range: (min: number, max: number) => Validator<number>;
204
+ pattern: (regex: RegExp) => Validator<string>;
205
+ };
206
+ interface PropDef<T = unknown> {
207
+ type?: Validator<T>;
208
+ required?: boolean;
209
+ default?: T | (() => T);
210
+ validator?: Validator<T>;
211
+ }
212
+ type PropSchema<Props> = {
213
+ [K in keyof Props]: PropDef<Props[K]> | Validator<Props[K]>;
214
+ };
215
+ /**
216
+ * Validate props against a schema. Returns validated props with defaults applied.
217
+ * In production mode (process.env.NODE_ENV === 'production'), validation is skipped
218
+ * and only defaults are applied for performance.
219
+ */
220
+ declare function validateProps<Props extends Record<string, unknown>>(props: Partial<Props>, schema: PropSchema<Props>): Props;
221
+ /**
222
+ * Define a component with runtime prop validation.
223
+ * Validates props in development mode, applies defaults, then calls setup.
224
+ */
225
+ declare function defineStrictComponent<Props extends Record<string, unknown>>(config: {
226
+ name: string;
227
+ props: PropSchema<Props>;
228
+ setup: (props: Props) => HTMLElement;
229
+ }): (props: Partial<Props>) => HTMLElement;
230
+ /**
231
+ * Assert that a value satisfies a contract at runtime.
232
+ * No-op in production builds.
233
+ */
234
+ declare function assertType<T>(value: unknown, validator: Validator<T>, label?: string): asserts value is T;
235
+ /**
236
+ * Create a type guard function from a validator.
237
+ */
238
+ declare function createGuard<T>(validator: Validator<T>): (value: unknown) => value is T;
239
+
240
+ export { type ComponentProps as C, type PropDef as P, RenderProp as R, type Validator as V, type PropSchema as a, assertType as b, compose as c, createGuard as d, createSlots as e, defineComponent as f, defineSlottedComponent as g, defineStrictComponent as h, validators as i, withDefaults as j, withProps as k, withWrapper as l, validateProps as v, withBoundary as w };
@@ -0,0 +1,240 @@
1
+ /**
2
+ * Higher-order component utilities for SibuJS.
3
+ * These functions wrap or compose components to add behavior.
4
+ */
5
+ type Component<P = unknown> = (props: P) => HTMLElement;
6
+ /**
7
+ * Wraps a component with additional behavior that runs before/after rendering.
8
+ *
9
+ * @param WrappedComponent The component to wrap
10
+ * @param wrapper Function that receives the component and its props, returns enhanced element
11
+ * @returns A new component function
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const WithLogging = withWrapper(MyComponent, (Comp, props) => {
16
+ * console.log("Rendering with props:", props);
17
+ * return Comp(props);
18
+ * });
19
+ * ```
20
+ */
21
+ declare function withWrapper<P>(WrappedComponent: Component<P>, wrapper: (component: Component<P>, props: P) => HTMLElement): Component<P>;
22
+ /**
23
+ * Adds default props to a component. Missing props are filled from defaults.
24
+ *
25
+ * @param component The component to wrap
26
+ * @param defaults Default prop values
27
+ * @returns A new component with defaults applied
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const Button = withDefaults(RawButton, { type: "button", disabled: false });
32
+ * Button({ nodes: "Click" }); // type="button", disabled=false automatically
33
+ * ```
34
+ */
35
+ declare function withDefaults<P extends Record<string, unknown>>(component: Component<P>, defaults: Partial<P>): Component<Partial<P>>;
36
+ /**
37
+ * Composes multiple HOC wrappers into a single wrapper.
38
+ * Applied from right to left (like function composition).
39
+ *
40
+ * @param wrappers Array of HOC functions
41
+ * @returns A function that applies all wrappers to a component
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * const enhance = compose(withAuth, withLogging, withTheme);
46
+ * const EnhancedPage = enhance(Page);
47
+ * ```
48
+ */
49
+ declare function compose(...wrappers: Array<(component: Component) => Component>): (component: Component) => Component;
50
+
51
+ /**
52
+ * RenderProp implements the render-prop pattern.
53
+ * The render function receives data and returns DOM nodes.
54
+ */
55
+ declare function RenderProp<T>(props: {
56
+ data: () => T;
57
+ render: (data: T) => HTMLElement;
58
+ }): HTMLElement;
59
+ /**
60
+ * withBoundary creates an isolated component boundary for debugging.
61
+ * Wraps component output in a named container with error isolation.
62
+ */
63
+ declare function withBoundary(name: string, component: (props?: unknown) => HTMLElement): (props?: unknown) => HTMLElement;
64
+ /**
65
+ * Slot pattern — provides named slots for component composition.
66
+ */
67
+ declare function createSlots(slots: Record<string, () => HTMLElement | HTMLElement[] | null>): {
68
+ renderSlot: (name: string, fallback?: () => HTMLElement) => HTMLElement | null;
69
+ hasSlot: (name: string) => boolean;
70
+ };
71
+
72
+ /**
73
+ * Functional component props with TypeScript inference for SibuJS.
74
+ *
75
+ * Provides utilities to define typed components with prop defaults,
76
+ * nodes slots, and prop mapping — all with full TypeScript inference.
77
+ */
78
+ /**
79
+ * Extract the props type from a component defined with defineComponent.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * const Button = defineComponent<{ label: string }>({
84
+ * setup(props) { ... }
85
+ * });
86
+ * type ButtonProps = ComponentProps<typeof Button>; // { label: string }
87
+ * ```
88
+ */
89
+ type ComponentProps<T> = T extends (props: infer P) => HTMLElement ? P : never;
90
+ /**
91
+ * Props that include an optional nodes slot.
92
+ */
93
+ type WithNodes<Props> = Props & {
94
+ nodes?: Node | Node[];
95
+ };
96
+ /**
97
+ * Define a typed component with props inference, defaults, and a setup function.
98
+ *
99
+ * The `setup` function receives merged props (defaults + provided) and must
100
+ * return an HTMLElement. TypeScript infers the full props type from the generic.
101
+ *
102
+ * @param config Component configuration with optional defaults and a setup function
103
+ * @returns A component function that accepts props and returns an HTMLElement
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * const Button = defineComponent<{ label: string; variant?: 'primary' | 'secondary'; disabled?: boolean }>({
108
+ * defaults: { variant: 'primary', disabled: false },
109
+ * setup(props) {
110
+ * return button({
111
+ * class: `btn btn-${props.variant}`,
112
+ * disabled: props.disabled,
113
+ * nodes: props.label
114
+ * });
115
+ * }
116
+ * });
117
+ *
118
+ * // Usage: Button({ label: 'Click me' }) — TypeScript infers props
119
+ * ```
120
+ */
121
+ declare function defineComponent<Props extends Record<string, unknown>>(config: {
122
+ defaults?: Partial<Props>;
123
+ setup: (props: Props) => HTMLElement;
124
+ }): (props: Props) => HTMLElement;
125
+ /**
126
+ * Create a component with nodes slot support.
127
+ *
128
+ * Nodes are passed as a special `nodes` prop alongside the component's
129
+ * own props. This enables composition patterns where a parent component
130
+ * wraps arbitrary child content.
131
+ *
132
+ * @param config Component configuration with optional defaults and a setup function
133
+ * @returns A component function that accepts props (including nodes) and returns an HTMLElement
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * const Card = defineSlottedComponent<{ title: string }>({
138
+ * setup(props) {
139
+ * const el = div({ class: 'card' });
140
+ * el.appendChild(h2({ nodes: props.title }));
141
+ * if (props.nodes) {
142
+ * const nodes = Array.isArray(props.nodes) ? props.nodes : [props.nodes];
143
+ * nodes.forEach(child => el.appendChild(child));
144
+ * }
145
+ * return el;
146
+ * }
147
+ * });
148
+ *
149
+ * // Usage: Card({ title: 'Hello', nodes: p({ nodes: 'World' }) })
150
+ * ```
151
+ */
152
+ declare function defineSlottedComponent<Props extends Record<string, unknown>>(config: {
153
+ defaults?: Partial<Props>;
154
+ setup: (props: WithNodes<Props>) => HTMLElement;
155
+ }): (props: WithNodes<Props>) => HTMLElement;
156
+ /**
157
+ * Higher-order helper to create a component that maps outer props to inner props.
158
+ *
159
+ * Useful for adapting a generic component to a specific use case by transforming
160
+ * the prop interface without modifying the original component.
161
+ *
162
+ * @param component The inner component to forward mapped props to
163
+ * @param mapProps A function that transforms outer props into inner props
164
+ * @returns A new component that accepts outer props
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * const IconButton = defineComponent<{ icon: string; label: string; size: number }>({
169
+ * setup(props) { ... }
170
+ * });
171
+ *
172
+ * const SmallIconButton = withProps(IconButton, (outer: { icon: string; label: string }) => ({
173
+ * icon: outer.icon,
174
+ * label: outer.label,
175
+ * size: 16
176
+ * }));
177
+ *
178
+ * // Usage: SmallIconButton({ icon: 'star', label: 'Favorite' })
179
+ * ```
180
+ */
181
+ declare function withProps<OuterProps extends Record<string, unknown>, InnerProps extends Record<string, unknown>>(component: (props: InnerProps) => HTMLElement, mapProps: (outer: OuterProps) => InnerProps): (props: OuterProps) => HTMLElement;
182
+
183
+ /**
184
+ * Runtime prop validation and strict typing contracts for SibuJS.
185
+ * Provides runtime type checking for component props in development mode.
186
+ */
187
+ /** Validator function: returns true if valid, or an error message string. */
188
+ type Validator<T = unknown> = (value: T, propName: string) => true | string;
189
+ /** Built-in validators */
190
+ declare const validators: {
191
+ string: Validator;
192
+ number: Validator;
193
+ boolean: Validator;
194
+ function: Validator;
195
+ object: Validator;
196
+ array: Validator;
197
+ required: Validator;
198
+ oneOf: <T>(...values: T[]) => Validator<T>;
199
+ instanceOf: <T>(ctor: new (...args: unknown[]) => T) => Validator<T>;
200
+ arrayOf: (itemValidator: Validator) => Validator<unknown[]>;
201
+ shape: (schema: Record<string, Validator>) => Validator<Record<string, unknown>>;
202
+ optional: (validator: Validator) => Validator;
203
+ range: (min: number, max: number) => Validator<number>;
204
+ pattern: (regex: RegExp) => Validator<string>;
205
+ };
206
+ interface PropDef<T = unknown> {
207
+ type?: Validator<T>;
208
+ required?: boolean;
209
+ default?: T | (() => T);
210
+ validator?: Validator<T>;
211
+ }
212
+ type PropSchema<Props> = {
213
+ [K in keyof Props]: PropDef<Props[K]> | Validator<Props[K]>;
214
+ };
215
+ /**
216
+ * Validate props against a schema. Returns validated props with defaults applied.
217
+ * In production mode (process.env.NODE_ENV === 'production'), validation is skipped
218
+ * and only defaults are applied for performance.
219
+ */
220
+ declare function validateProps<Props extends Record<string, unknown>>(props: Partial<Props>, schema: PropSchema<Props>): Props;
221
+ /**
222
+ * Define a component with runtime prop validation.
223
+ * Validates props in development mode, applies defaults, then calls setup.
224
+ */
225
+ declare function defineStrictComponent<Props extends Record<string, unknown>>(config: {
226
+ name: string;
227
+ props: PropSchema<Props>;
228
+ setup: (props: Props) => HTMLElement;
229
+ }): (props: Partial<Props>) => HTMLElement;
230
+ /**
231
+ * Assert that a value satisfies a contract at runtime.
232
+ * No-op in production builds.
233
+ */
234
+ declare function assertType<T>(value: unknown, validator: Validator<T>, label?: string): asserts value is T;
235
+ /**
236
+ * Create a type guard function from a validator.
237
+ */
238
+ declare function createGuard<T>(validator: Validator<T>): (value: unknown) => value is T;
239
+
240
+ export { type ComponentProps as C, type PropDef as P, RenderProp as R, type Validator as V, type PropSchema as a, assertType as b, compose as c, createGuard as d, createSlots as e, defineComponent as f, defineSlottedComponent as g, defineStrictComponent as h, validators as i, withDefaults as j, withProps as k, withWrapper as l, validateProps as v, withBoundary as w };
package/dist/data.cjs CHANGED
@@ -1265,6 +1265,13 @@ async function preloadRoute(route, context2) {
1265
1265
  }
1266
1266
 
1267
1267
  // src/ui/socket.ts
1268
+ function validateWsUrl(raw) {
1269
+ const trimmed = raw.replace(/[\x00-\x20\x7f-\x9f]+/g, "").trim();
1270
+ if (!trimmed) return null;
1271
+ const lower = trimmed.toLowerCase();
1272
+ if (lower.startsWith("ws://") || lower.startsWith("wss://")) return trimmed;
1273
+ return null;
1274
+ }
1268
1275
  function socket(url, options) {
1269
1276
  const autoReconnect = options?.autoReconnect ?? false;
1270
1277
  const reconnectDelay = options?.reconnectDelay ?? 1e3;
@@ -1283,8 +1290,13 @@ function socket(url, options) {
1283
1290
  }
1284
1291
  function connect() {
1285
1292
  if (disposed) return;
1293
+ const safeUrl = validateWsUrl(getUrl());
1294
+ if (safeUrl === null) {
1295
+ setStatus("closed");
1296
+ return;
1297
+ }
1286
1298
  setStatus("connecting");
1287
- ws = new WebSocket(getUrl(), protocols);
1299
+ ws = new WebSocket(safeUrl, protocols);
1288
1300
  ws.onopen = () => {
1289
1301
  setStatus("open");
1290
1302
  reconnectCount = 0;
@@ -1345,7 +1357,23 @@ function socket(url, options) {
1345
1357
  return { data, status, send, close, dispose };
1346
1358
  }
1347
1359
 
1360
+ // src/utils/sanitize.ts
1361
+ function sanitizeUrl(url) {
1362
+ const trimmed = url.replace(/[\x00-\x20\x7f-\x9f]+/g, "").trim();
1363
+ if (!trimmed) return "";
1364
+ const lower = trimmed.toLowerCase();
1365
+ if (lower.startsWith("javascript:") || lower.startsWith("data:") || lower.startsWith("vbscript:") || lower.startsWith("blob:")) {
1366
+ return "";
1367
+ }
1368
+ return trimmed;
1369
+ }
1370
+
1348
1371
  // src/ui/stream.ts
1372
+ function validateSseUrl(raw) {
1373
+ const safe = sanitizeUrl(raw);
1374
+ if (!safe) return null;
1375
+ return safe;
1376
+ }
1349
1377
  function stream(url, options) {
1350
1378
  const autoReconnect = options?.autoReconnect ?? false;
1351
1379
  const [data, setData] = signal(null);
@@ -1356,8 +1384,13 @@ function stream(url, options) {
1356
1384
  let reconnectTimer = null;
1357
1385
  function connect() {
1358
1386
  if (disposed) return;
1387
+ const safeUrl = validateSseUrl(url);
1388
+ if (safeUrl === null) {
1389
+ setStatus("closed");
1390
+ return;
1391
+ }
1359
1392
  setStatus("connecting");
1360
- source = new EventSource(url, {
1393
+ source = new EventSource(safeUrl, {
1361
1394
  withCredentials: options?.withCredentials ?? false
1362
1395
  });
1363
1396
  source.onopen = () => {
package/dist/data.d.cts CHANGED
@@ -400,6 +400,9 @@ declare function preloadRoute(route: LoaderRoute, context: {
400
400
  /**
401
401
  * socket provides a reactive WebSocket connection with auto-reconnect
402
402
  * and optional heartbeat support.
403
+ *
404
+ * Security: the URL is validated against `ws://` / `wss://` only —
405
+ * `javascript:` and similar schemes are refused (status stays `"closed"`).
403
406
  */
404
407
  declare function socket(url: string | (() => string), options?: {
405
408
  protocols?: string | string[];
@@ -421,6 +424,10 @@ declare function socket(url: string | (() => string), options?: {
421
424
  /**
422
425
  * stream provides reactive Server-Sent Events (SSE) integration.
423
426
  * Wraps the EventSource API with reactive state for data, event name, and connection status.
427
+ *
428
+ * Security: the URL is passed through `sanitizeUrl()` — `javascript:`,
429
+ * `data:`, `vbscript:`, and `blob:` URIs are refused and the stream
430
+ * stays in `"closed"` state.
424
431
  */
425
432
  declare function stream(url: string, options?: {
426
433
  withCredentials?: boolean;
package/dist/data.d.ts CHANGED
@@ -400,6 +400,9 @@ declare function preloadRoute(route: LoaderRoute, context: {
400
400
  /**
401
401
  * socket provides a reactive WebSocket connection with auto-reconnect
402
402
  * and optional heartbeat support.
403
+ *
404
+ * Security: the URL is validated against `ws://` / `wss://` only —
405
+ * `javascript:` and similar schemes are refused (status stays `"closed"`).
403
406
  */
404
407
  declare function socket(url: string | (() => string), options?: {
405
408
  protocols?: string | string[];
@@ -421,6 +424,10 @@ declare function socket(url: string | (() => string), options?: {
421
424
  /**
422
425
  * stream provides reactive Server-Sent Events (SSE) integration.
423
426
  * Wraps the EventSource API with reactive state for data, event name, and connection status.
427
+ *
428
+ * Security: the URL is passed through `sanitizeUrl()` — `javascript:`,
429
+ * `data:`, `vbscript:`, and `blob:` URIs are refused and the stream
430
+ * stays in `"closed"` state.
424
431
  */
425
432
  declare function stream(url: string, options?: {
426
433
  withCredentials?: boolean;
package/dist/data.js CHANGED
@@ -19,14 +19,15 @@ import {
19
19
  syncAdapter,
20
20
  throttle,
21
21
  withRetry
22
- } from "./chunk-Z6POF5YC.js";
23
- import "./chunk-WR5D4EGH.js";
24
- import "./chunk-L6JRBDNS.js";
25
- import "./chunk-6SA3QQES.js";
26
- import "./chunk-CHJ27IGK.js";
27
- import "./chunk-V2XTI523.js";
28
- import "./chunk-UNXCEF6S.js";
29
- import "./chunk-MLKGABMK.js";
22
+ } from "./chunk-JAKHTMQU.js";
23
+ import "./chunk-BGN5ZMP4.js";
24
+ import "./chunk-NEKUBFPT.js";
25
+ import "./chunk-CMBFNA7L.js";
26
+ import "./chunk-CHF5OHIA.js";
27
+ import "./chunk-EUZND3CB.js";
28
+ import "./chunk-WZSPOOER.js";
29
+ import "./chunk-ZD6OAMTH.js";
30
+ import "./chunk-5X6PP2UK.js";
30
31
  export {
31
32
  calculateDelay,
32
33
  clearQueryCache,