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,26 @@
1
+ import {
2
+ signal
3
+ } from "./chunk-WZSPOOER.js";
4
+
5
+ // src/core/rendering/context.ts
6
+ function context(defaultValue) {
7
+ const [getValue, setValue] = signal(defaultValue);
8
+ return {
9
+ provide(value) {
10
+ setValue(value);
11
+ },
12
+ use() {
13
+ return getValue;
14
+ },
15
+ get() {
16
+ return getValue();
17
+ },
18
+ set(value) {
19
+ setValue(value);
20
+ }
21
+ };
22
+ }
23
+
24
+ export {
25
+ context
26
+ };
@@ -0,0 +1,365 @@
1
+ import {
2
+ createPlugin
3
+ } from "./chunk-K5ZUMYVS.js";
4
+ import {
5
+ tagFactory
6
+ } from "./chunk-F3FA4F32.js";
7
+ import {
8
+ derived
9
+ } from "./chunk-NEKUBFPT.js";
10
+ import {
11
+ effect
12
+ } from "./chunk-CHF5OHIA.js";
13
+ import {
14
+ batch,
15
+ signal
16
+ } from "./chunk-WZSPOOER.js";
17
+
18
+ // src/ecosystem/adapters/mobx.ts
19
+ function mobXAdapter(options) {
20
+ return createPlugin("sibu-mobx", (ctx) => {
21
+ const { autorun } = options;
22
+ const disposers = [];
23
+ function fromMobX(expression) {
24
+ const [getValue, setValue] = signal(expression());
25
+ const disposer = autorun(() => {
26
+ const newValue = expression();
27
+ batch(() => {
28
+ setValue(newValue);
29
+ });
30
+ });
31
+ disposers.push(disposer);
32
+ return getValue;
33
+ }
34
+ function toMobX(sibuGetter, callback) {
35
+ return effect(() => {
36
+ callback(sibuGetter());
37
+ });
38
+ }
39
+ function destroy() {
40
+ for (const disposer of disposers) {
41
+ disposer();
42
+ }
43
+ disposers.length = 0;
44
+ }
45
+ const api = { fromMobX, toMobX, destroy };
46
+ ctx.provide("mobx", api);
47
+ });
48
+ }
49
+
50
+ // src/ecosystem/adapters/redux.ts
51
+ function reduxAdapter(options) {
52
+ return createPlugin("sibu-redux", (ctx) => {
53
+ const { store } = options;
54
+ const [getState, setState] = signal(store.getState());
55
+ const unsubscribe = store.subscribe(() => {
56
+ batch(() => {
57
+ setState(store.getState());
58
+ });
59
+ });
60
+ function useSelector(selector) {
61
+ return derived(() => selector(getState()));
62
+ }
63
+ const api = {
64
+ getState,
65
+ useSelector,
66
+ dispatch: store.dispatch.bind(store),
67
+ destroy: unsubscribe
68
+ };
69
+ ctx.provide("redux", api);
70
+ });
71
+ }
72
+
73
+ // src/ecosystem/adapters/zustand.ts
74
+ function zustandAdapter(options) {
75
+ return createPlugin("sibu-zustand", (ctx) => {
76
+ const { store } = options;
77
+ const [getState, setSibuState] = signal(store.getState());
78
+ const unsubscribe = store.subscribe((state) => {
79
+ batch(() => {
80
+ setSibuState(state);
81
+ });
82
+ });
83
+ function useSelector(selector) {
84
+ return derived(() => selector(getState()));
85
+ }
86
+ const api = {
87
+ getState,
88
+ useSelector,
89
+ setState: store.setState.bind(store),
90
+ destroy() {
91
+ unsubscribe();
92
+ store.destroy();
93
+ }
94
+ };
95
+ ctx.provide("zustand", api);
96
+ });
97
+ }
98
+
99
+ // src/ecosystem/ui/componentAdapter.ts
100
+ function createTheme(initial) {
101
+ const [getConfig, setConfig] = signal(initial);
102
+ function resolveClass(component, variant) {
103
+ const config = getConfig();
104
+ const overrideKey = variant ? `${component}-${variant}` : component;
105
+ if (config.classOverrides?.[overrideKey]) {
106
+ return config.classOverrides[overrideKey];
107
+ }
108
+ const base = `${config.prefix}-${component}`;
109
+ return variant ? `${base} ${config.prefix}-${component}--${variant}` : base;
110
+ }
111
+ function setTheme(partial) {
112
+ setConfig((prev) => ({ ...prev, ...partial }));
113
+ }
114
+ return { config: getConfig, setTheme, resolveClass };
115
+ }
116
+ function componentAdapter(config) {
117
+ const theme = createTheme({ prefix: config.prefix });
118
+ const components = {};
119
+ for (const [name, mapping] of Object.entries(config.components)) {
120
+ const factory = tagFactory(mapping.tag || "div");
121
+ components[name] = (props = {}) => {
122
+ const { variant, size, class: userClass, ...rest } = props;
123
+ const classes = [mapping.baseClass];
124
+ if (variant && mapping.variants?.[variant]) {
125
+ classes.push(mapping.variants[variant]);
126
+ }
127
+ if (size && mapping.sizes?.[size]) {
128
+ classes.push(mapping.sizes[size]);
129
+ }
130
+ let finalClass;
131
+ if (typeof userClass === "function") {
132
+ finalClass = () => {
133
+ const extra = userClass();
134
+ return extra ? `${classes.join(" ")} ${extra}` : classes.join(" ");
135
+ };
136
+ } else if (typeof userClass === "string" && userClass) {
137
+ finalClass = `${classes.join(" ")} ${userClass}`;
138
+ } else {
139
+ finalClass = classes.join(" ");
140
+ }
141
+ const mergedProps = {
142
+ ...mapping.defaultProps,
143
+ ...rest,
144
+ class: finalClass
145
+ };
146
+ return factory(mergedProps);
147
+ };
148
+ }
149
+ return { name: config.name, components, theme };
150
+ }
151
+
152
+ // src/ecosystem/ui/antd.ts
153
+ var antdConfig = {
154
+ name: "antd",
155
+ prefix: "ant",
156
+ components: {
157
+ Button: {
158
+ tag: "button",
159
+ baseClass: "ant-btn",
160
+ variants: {
161
+ primary: "ant-btn-primary",
162
+ dashed: "ant-btn-dashed",
163
+ text: "ant-btn-text",
164
+ link: "ant-btn-link",
165
+ default: "ant-btn-default",
166
+ danger: "ant-btn-dangerous"
167
+ },
168
+ sizes: {
169
+ sm: "ant-btn-sm",
170
+ lg: "ant-btn-lg"
171
+ },
172
+ defaultProps: { type: "button" }
173
+ },
174
+ Input: {
175
+ tag: "input",
176
+ baseClass: "ant-input",
177
+ sizes: {
178
+ sm: "ant-input-sm",
179
+ lg: "ant-input-lg"
180
+ }
181
+ },
182
+ Card: {
183
+ tag: "div",
184
+ baseClass: "ant-card",
185
+ variants: {
186
+ bordered: "ant-card-bordered"
187
+ }
188
+ },
189
+ Modal: {
190
+ tag: "div",
191
+ baseClass: "ant-modal"
192
+ },
193
+ Tag: {
194
+ tag: "span",
195
+ baseClass: "ant-tag",
196
+ variants: {
197
+ success: "ant-tag-success",
198
+ error: "ant-tag-error",
199
+ warning: "ant-tag-warning",
200
+ processing: "ant-tag-processing"
201
+ }
202
+ },
203
+ Badge: {
204
+ tag: "span",
205
+ baseClass: "ant-badge"
206
+ },
207
+ Avatar: {
208
+ tag: "span",
209
+ baseClass: "ant-avatar",
210
+ sizes: {
211
+ sm: "ant-avatar-sm",
212
+ lg: "ant-avatar-lg"
213
+ }
214
+ }
215
+ }
216
+ };
217
+ var antdAdapter = componentAdapter(antdConfig);
218
+
219
+ // src/ecosystem/ui/chakra.ts
220
+ var chakraConfig = {
221
+ name: "chakra",
222
+ prefix: "chakra",
223
+ components: {
224
+ Button: {
225
+ tag: "button",
226
+ baseClass: "chakra-button",
227
+ variants: {
228
+ solid: "chakra-button--solid",
229
+ outline: "chakra-button--outline",
230
+ ghost: "chakra-button--ghost",
231
+ link: "chakra-button--link"
232
+ },
233
+ sizes: {
234
+ xs: "chakra-button--xs",
235
+ sm: "chakra-button--sm",
236
+ md: "chakra-button--md",
237
+ lg: "chakra-button--lg"
238
+ },
239
+ defaultProps: { type: "button" }
240
+ },
241
+ Input: {
242
+ tag: "input",
243
+ baseClass: "chakra-input",
244
+ variants: {
245
+ outline: "chakra-input--outline",
246
+ filled: "chakra-input--filled",
247
+ flushed: "chakra-input--flushed",
248
+ unstyled: "chakra-input--unstyled"
249
+ },
250
+ sizes: {
251
+ xs: "chakra-input--xs",
252
+ sm: "chakra-input--sm",
253
+ md: "chakra-input--md",
254
+ lg: "chakra-input--lg"
255
+ }
256
+ },
257
+ Card: {
258
+ tag: "div",
259
+ baseClass: "chakra-card",
260
+ variants: {
261
+ elevated: "chakra-card--elevated",
262
+ outline: "chakra-card--outline",
263
+ filled: "chakra-card--filled",
264
+ unstyled: "chakra-card--unstyled"
265
+ }
266
+ },
267
+ Modal: {
268
+ tag: "div",
269
+ baseClass: "chakra-modal__content"
270
+ },
271
+ Badge: {
272
+ tag: "span",
273
+ baseClass: "chakra-badge",
274
+ variants: {
275
+ solid: "chakra-badge--solid",
276
+ subtle: "chakra-badge--subtle",
277
+ outline: "chakra-badge--outline"
278
+ }
279
+ },
280
+ Stack: {
281
+ tag: "div",
282
+ baseClass: "chakra-stack",
283
+ variants: {
284
+ horizontal: "chakra-stack--horizontal",
285
+ vertical: "chakra-stack--vertical"
286
+ }
287
+ }
288
+ }
289
+ };
290
+ var chakraAdapter = componentAdapter(chakraConfig);
291
+
292
+ // src/ecosystem/ui/material.ts
293
+ var materialConfig = {
294
+ name: "material",
295
+ prefix: "mdc",
296
+ components: {
297
+ Button: {
298
+ tag: "button",
299
+ baseClass: "mdc-button",
300
+ variants: {
301
+ raised: "mdc-button--raised",
302
+ outlined: "mdc-button--outlined",
303
+ text: "mdc-button--text",
304
+ unelevated: "mdc-button--unelevated"
305
+ },
306
+ sizes: {
307
+ sm: "mdc-button--dense"
308
+ },
309
+ defaultProps: { type: "button" }
310
+ },
311
+ Input: {
312
+ tag: "div",
313
+ baseClass: "mdc-text-field",
314
+ variants: {
315
+ outlined: "mdc-text-field--outlined",
316
+ filled: "mdc-text-field--filled"
317
+ }
318
+ },
319
+ Card: {
320
+ tag: "div",
321
+ baseClass: "mdc-card",
322
+ variants: {
323
+ outlined: "mdc-card--outlined",
324
+ elevated: "mdc-card--elevated"
325
+ }
326
+ },
327
+ Modal: {
328
+ tag: "div",
329
+ baseClass: "mdc-dialog",
330
+ variants: {
331
+ fullscreen: "mdc-dialog--fullscreen"
332
+ }
333
+ },
334
+ Chip: {
335
+ tag: "span",
336
+ baseClass: "mdc-chip",
337
+ variants: {
338
+ outlined: "mdc-chip--outlined"
339
+ }
340
+ },
341
+ List: {
342
+ tag: "ul",
343
+ baseClass: "mdc-list",
344
+ variants: {
345
+ dense: "mdc-list--dense"
346
+ }
347
+ },
348
+ ListItem: {
349
+ tag: "li",
350
+ baseClass: "mdc-list-item"
351
+ }
352
+ }
353
+ };
354
+ var materialAdapter = componentAdapter(materialConfig);
355
+
356
+ export {
357
+ mobXAdapter,
358
+ reduxAdapter,
359
+ zustandAdapter,
360
+ createTheme,
361
+ componentAdapter,
362
+ antdAdapter,
363
+ chakraAdapter,
364
+ materialAdapter
365
+ };
@@ -0,0 +1,61 @@
1
+ import {
2
+ isSSR
3
+ } from "./chunk-EUZND3CB.js";
4
+ import {
5
+ track,
6
+ untracked
7
+ } from "./chunk-ZD6OAMTH.js";
8
+ import {
9
+ devAssert
10
+ } from "./chunk-5X6PP2UK.js";
11
+
12
+ // src/core/signals/effect.ts
13
+ var _g = globalThis;
14
+ function on(deps, handler) {
15
+ let prev;
16
+ let first = true;
17
+ return () => {
18
+ const value = deps();
19
+ if (first) {
20
+ first = false;
21
+ prev = value;
22
+ untracked(() => handler(value, void 0));
23
+ } else {
24
+ const p = prev;
25
+ prev = value;
26
+ untracked(() => handler(value, p));
27
+ }
28
+ };
29
+ }
30
+ function effect(effectFn, options) {
31
+ devAssert(typeof effectFn === "function", "effect: argument must be a function.");
32
+ if (isSSR()) return () => {
33
+ };
34
+ const onError = options?.onError;
35
+ const wrappedFn = onError ? () => {
36
+ try {
37
+ effectFn();
38
+ } catch (err) {
39
+ onError(err);
40
+ }
41
+ } : effectFn;
42
+ let cleanupHandle = () => {
43
+ };
44
+ const subscriber = () => {
45
+ cleanupHandle();
46
+ cleanupHandle = track(wrappedFn, subscriber);
47
+ };
48
+ cleanupHandle = track(wrappedFn, subscriber);
49
+ const hook = _g.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
50
+ if (hook) hook.emit("effect:create", { effectFn });
51
+ return () => {
52
+ const h = _g.__SIBU_DEVTOOLS_GLOBAL_HOOK__;
53
+ if (h) h.emit("effect:destroy", { effectFn });
54
+ cleanupHandle();
55
+ };
56
+ }
57
+
58
+ export {
59
+ on,
60
+ effect
61
+ };
@@ -0,0 +1,27 @@
1
+ // src/utils/sanitize.ts
2
+ function sanitizeUrl(url) {
3
+ const trimmed = url.replace(/[\x00-\x20\x7f-\x9f]+/g, "").trim();
4
+ if (!trimmed) return "";
5
+ const lower = trimmed.toLowerCase();
6
+ if (lower.startsWith("javascript:") || lower.startsWith("data:") || lower.startsWith("vbscript:") || lower.startsWith("blob:")) {
7
+ return "";
8
+ }
9
+ return trimmed;
10
+ }
11
+ function sanitizeCSSValue(value) {
12
+ const lower = value.toLowerCase().replace(/\s+/g, "");
13
+ if (lower.includes("url(") || lower.includes("expression(") || lower.includes("javascript:") || lower.includes("-moz-binding")) {
14
+ return "";
15
+ }
16
+ return value;
17
+ }
18
+ var URL_ATTRIBUTES = /* @__PURE__ */ new Set(["href", "src", "action", "formaction", "cite", "poster", "background", "srcset"]);
19
+ function isUrlAttribute(attr) {
20
+ return URL_ATTRIBUTES.has(attr);
21
+ }
22
+
23
+ export {
24
+ sanitizeUrl,
25
+ sanitizeCSSValue,
26
+ isUrlAttribute
27
+ };
@@ -0,0 +1,178 @@
1
+ // src/patterns/hoc.ts
2
+ function withWrapper(WrappedComponent, wrapper) {
3
+ return (props) => wrapper(WrappedComponent, props);
4
+ }
5
+ function withDefaults(component, defaults) {
6
+ return (props) => component({ ...defaults, ...props });
7
+ }
8
+ function compose(...wrappers) {
9
+ return (component) => wrappers.reduceRight((comp, wrapper) => wrapper(comp), component);
10
+ }
11
+
12
+ // src/patterns/composable.ts
13
+ function RenderProp(props) {
14
+ return props.render(props.data());
15
+ }
16
+ function withBoundary(name, component) {
17
+ return (props) => {
18
+ const wrapper = document.createElement("div");
19
+ wrapper.setAttribute("data-sibu-boundary", name);
20
+ try {
21
+ const el = component(props);
22
+ wrapper.appendChild(el);
23
+ } catch (error) {
24
+ const errorEl = document.createElement("div");
25
+ errorEl.setAttribute("data-sibu-boundary-error", name);
26
+ errorEl.style.cssText = "color: red; border: 1px solid red; padding: 8px; margin: 4px;";
27
+ errorEl.textContent = `[${name}] ${error instanceof Error ? error.message : String(error)}`;
28
+ wrapper.appendChild(errorEl);
29
+ }
30
+ return wrapper;
31
+ };
32
+ }
33
+ function createSlots(slots) {
34
+ return {
35
+ renderSlot(name, fallback) {
36
+ const slotFn = slots[name];
37
+ if (slotFn) {
38
+ const result = slotFn();
39
+ if (Array.isArray(result)) {
40
+ const fragment = document.createElement("div");
41
+ fragment.style.display = "contents";
42
+ for (const el of result) fragment.appendChild(el);
43
+ return fragment;
44
+ }
45
+ return result;
46
+ }
47
+ return fallback ? fallback() : null;
48
+ },
49
+ hasSlot(name) {
50
+ return name in slots;
51
+ }
52
+ };
53
+ }
54
+
55
+ // src/patterns/componentProps.ts
56
+ function defineComponent(config) {
57
+ const { defaults, setup } = config;
58
+ return (props) => {
59
+ const merged = defaults ? { ...defaults, ...props } : props;
60
+ return setup(merged);
61
+ };
62
+ }
63
+ function defineSlottedComponent(config) {
64
+ const { defaults, setup } = config;
65
+ return (props) => {
66
+ const merged = defaults ? { ...defaults, ...props } : props;
67
+ return setup(merged);
68
+ };
69
+ }
70
+ function withProps(component, mapProps) {
71
+ return (props) => component(mapProps(props));
72
+ }
73
+
74
+ // src/patterns/contracts.ts
75
+ var validators = {
76
+ string: ((value, name) => typeof value === "string" || `${name} must be a string, got ${typeof value}`),
77
+ number: ((value, name) => typeof value === "number" || `${name} must be a number, got ${typeof value}`),
78
+ boolean: ((value, name) => typeof value === "boolean" || `${name} must be a boolean, got ${typeof value}`),
79
+ function: ((value, name) => typeof value === "function" || `${name} must be a function, got ${typeof value}`),
80
+ object: ((value, name) => typeof value === "object" && value !== null || `${name} must be an object`),
81
+ array: ((value, name) => Array.isArray(value) || `${name} must be an array`),
82
+ required: ((value, name) => value != null || `${name} is required`),
83
+ oneOf: (...values) => (value, name) => values.includes(value) || `${name} must be one of: ${values.join(", ")}`,
84
+ instanceOf: (ctor) => (value, name) => value instanceof ctor || `${name} must be an instance of ${ctor.name}`,
85
+ arrayOf: (itemValidator) => (value, name) => {
86
+ if (!Array.isArray(value)) return `${name} must be an array`;
87
+ for (let i = 0; i < value.length; i++) {
88
+ const result = itemValidator(value[i], `${name}[${i}]`);
89
+ if (result !== true) return result;
90
+ }
91
+ return true;
92
+ },
93
+ shape: (schema) => (value, name) => {
94
+ if (typeof value !== "object" || value === null) return `${name} must be an object`;
95
+ for (const [key, validator] of Object.entries(schema)) {
96
+ const result = validator(value[key], `${name}.${key}`);
97
+ if (result !== true) return result;
98
+ }
99
+ return true;
100
+ },
101
+ optional: (validator) => (value, name) => {
102
+ if (value == null) return true;
103
+ return validator(value, name);
104
+ },
105
+ range: (min, max) => (value, name) => {
106
+ if (typeof value !== "number") return `${name} must be a number`;
107
+ return value >= min && value <= max || `${name} must be between ${min} and ${max}`;
108
+ },
109
+ pattern: (regex) => (value, name) => {
110
+ if (typeof value !== "string") return `${name} must be a string`;
111
+ return regex.test(value) || `${name} must match pattern ${regex}`;
112
+ }
113
+ };
114
+ function validateProps(props, schema) {
115
+ const result = { ...props };
116
+ const errors = [];
117
+ const isDev = typeof process === "undefined" || process?.env?.NODE_ENV !== "production";
118
+ for (const [key, def] of Object.entries(schema)) {
119
+ const propDef = typeof def === "function" ? { type: def } : def;
120
+ if (result[key] == null && propDef.default !== void 0) {
121
+ result[key] = typeof propDef.default === "function" ? propDef.default() : propDef.default;
122
+ }
123
+ if (!isDev) continue;
124
+ if (propDef.required && result[key] == null) {
125
+ errors.push(`Prop '${key}' is required`);
126
+ continue;
127
+ }
128
+ if (result[key] == null) continue;
129
+ if (propDef.type) {
130
+ const typeResult = propDef.type(result[key], key);
131
+ if (typeResult !== true) errors.push(typeResult);
132
+ }
133
+ if (propDef.validator) {
134
+ const validResult = propDef.validator(result[key], key);
135
+ if (validResult !== true) errors.push(validResult);
136
+ }
137
+ }
138
+ if (errors.length > 0 && isDev) {
139
+ console.warn(`[SibuJS] Prop validation errors:
140
+ ${errors.map((e) => ` - ${e}`).join("\n")}`);
141
+ }
142
+ return result;
143
+ }
144
+ function defineStrictComponent(config) {
145
+ return (props) => {
146
+ const validated = validateProps(props, config.props);
147
+ return config.setup(validated);
148
+ };
149
+ }
150
+ function assertType(value, validator, label) {
151
+ if (typeof process !== "undefined" && process?.env?.NODE_ENV === "production") return;
152
+ const result = validator(value, label || "value");
153
+ if (result !== true) {
154
+ throw new TypeError(`[SibuJS Contract] ${result}`);
155
+ }
156
+ }
157
+ function createGuard(validator) {
158
+ return (value) => {
159
+ return validator(value, "value") === true;
160
+ };
161
+ }
162
+
163
+ export {
164
+ withWrapper,
165
+ withDefaults,
166
+ compose,
167
+ RenderProp,
168
+ withBoundary,
169
+ createSlots,
170
+ defineComponent,
171
+ defineSlottedComponent,
172
+ withProps,
173
+ validators,
174
+ validateProps,
175
+ defineStrictComponent,
176
+ assertType,
177
+ createGuard
178
+ };