sibujs 1.3.0 → 1.5.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 +105 -119
- package/dist/browser.cjs +53 -14
- package/dist/browser.d.cts +14 -9
- package/dist/browser.d.ts +14 -9
- package/dist/browser.js +4 -4
- package/dist/build.cjs +125 -135
- package/dist/build.d.cts +1 -1
- package/dist/build.d.ts +1 -1
- package/dist/build.js +11 -91
- package/dist/cdn.global.js +6 -6
- package/dist/chunk-5ZYQ6KDD.js +154 -0
- package/dist/chunk-6BMPXPUW.js +26 -0
- package/dist/chunk-7GRNSCFT.js +1097 -0
- package/dist/chunk-BGTHZHJ5.js +1016 -0
- package/dist/chunk-BMPL52BF.js +654 -0
- package/dist/chunk-CNZ35WI2.js +178 -0
- package/dist/chunk-GJPXRJ45.js +37 -0
- package/dist/chunk-JCDUJN2F.js +2779 -0
- package/dist/chunk-K4G4ZQNR.js +286 -0
- package/dist/chunk-M4NLBH4I.js +725 -0
- package/dist/chunk-MB6QFH3I.js +2776 -0
- package/dist/chunk-MYRV7VDM.js +742 -0
- package/dist/chunk-NZIIMDWI.js +84 -0
- package/dist/chunk-P3XWXJZU.js +282 -0
- package/dist/chunk-PDZQY43A.js +616 -0
- package/dist/chunk-RJ46C3CS.js +1293 -0
- package/dist/chunk-SFKNRVCU.js +292 -0
- package/dist/chunk-TDGZL5CU.js +365 -0
- package/dist/chunk-UHNL42EF.js +2730 -0
- package/dist/chunk-VAPYJN4X.js +368 -0
- package/dist/chunk-VQDZK23A.js +1023 -0
- package/dist/chunk-VQNQZCWJ.js +61 -0
- package/dist/chunk-XHK6BDAJ.js +76 -0
- package/dist/chunk-XUEEGU5O.js +409 -0
- package/dist/chunk-ZWKZCBO6.js +317 -0
- package/dist/contracts-ey_Qh8ef.d.cts +239 -0
- package/dist/contracts-ey_Qh8ef.d.ts +239 -0
- package/dist/contracts-xo5ckdRP.d.cts +240 -0
- package/dist/contracts-xo5ckdRP.d.ts +240 -0
- package/dist/customElement-BL3Uo8dL.d.cts +318 -0
- package/dist/customElement-BL3Uo8dL.d.ts +318 -0
- package/dist/data.cjs +52 -11
- package/dist/data.js +6 -6
- package/dist/devtools.cjs +22 -24
- package/dist/devtools.d.cts +1 -1
- package/dist/devtools.d.ts +1 -1
- package/dist/devtools.js +26 -28
- package/dist/ecosystem.cjs +31 -6
- package/dist/ecosystem.d.cts +4 -4
- package/dist/ecosystem.d.ts +4 -4
- package/dist/ecosystem.js +7 -7
- package/dist/extras.cjs +305 -131
- package/dist/extras.d.cts +3 -3
- package/dist/extras.d.ts +3 -3
- package/dist/extras.js +21 -29
- package/dist/index.cjs +124 -56
- package/dist/index.d.cts +60 -72
- package/dist/index.d.ts +60 -72
- package/dist/index.js +10 -14
- package/dist/motion.cjs +13 -2
- package/dist/motion.d.cts +1 -1
- package/dist/motion.d.ts +1 -1
- package/dist/motion.js +3 -3
- package/dist/patterns.cjs +91 -46
- package/dist/patterns.d.cts +46 -60
- package/dist/patterns.d.ts +46 -60
- package/dist/patterns.js +6 -14
- package/dist/performance.cjs +97 -12
- package/dist/performance.d.cts +6 -1
- package/dist/performance.d.ts +6 -1
- package/dist/performance.js +5 -3
- package/dist/plugins.cjs +20 -14
- package/dist/plugins.d.cts +3 -3
- package/dist/plugins.d.ts +3 -3
- package/dist/plugins.js +17 -19
- package/dist/ssr.cjs +9 -0
- package/dist/ssr.d.cts +1 -1
- package/dist/ssr.d.ts +1 -1
- package/dist/ssr.js +7 -7
- package/dist/testing.js +2 -2
- package/dist/ui.cjs +130 -53
- package/dist/ui.d.cts +13 -16
- package/dist/ui.d.ts +13 -16
- package/dist/ui.js +7 -9
- package/dist/widgets.cjs +31 -6
- package/dist/widgets.js +5 -5
- package/package.json +1 -1
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isSSR
|
|
3
|
+
} from "./chunk-EUZND3CB.js";
|
|
4
|
+
import {
|
|
5
|
+
track
|
|
6
|
+
} from "./chunk-K4G4ZQNR.js";
|
|
7
|
+
import {
|
|
8
|
+
devAssert
|
|
9
|
+
} from "./chunk-5X6PP2UK.js";
|
|
10
|
+
|
|
11
|
+
// src/core/signals/watch.ts
|
|
12
|
+
function watch(getter, callback) {
|
|
13
|
+
devAssert(typeof getter === "function", "watch: first argument must be a getter function.");
|
|
14
|
+
devAssert(typeof callback === "function", "watch: second argument must be a callback function.");
|
|
15
|
+
if (isSSR()) return () => {
|
|
16
|
+
};
|
|
17
|
+
let oldValue;
|
|
18
|
+
let first = true;
|
|
19
|
+
const subscriber = () => {
|
|
20
|
+
const newValue = getter();
|
|
21
|
+
if (first) {
|
|
22
|
+
oldValue = newValue;
|
|
23
|
+
first = false;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (!Object.is(newValue, oldValue)) {
|
|
27
|
+
callback(newValue, oldValue);
|
|
28
|
+
oldValue = newValue;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const teardown = track(subscriber);
|
|
32
|
+
return teardown;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
watch
|
|
37
|
+
};
|